Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C to C++ strings- wrapping

Name: Anonymous 2007-03-23 1:52 ID:691HhKaB

Hey, I'm developing using Allegro, and it uses C-style strings, which is starting to become a pain. For example, I have code such as:

addMessage("%s %d", getName().c_str(), getAge());

addMessage is just a printf kind of function that uses variable arguments to create a string that will go to Allegro's textout, which takes a char * among other things. This works fine, but what I'd rather have is something like:

addMessage << getName() << " " << getAge();

So, I really just need to do something with strings and streams. Could someone help me out with what specifically needs to be done to implement this?

Name: Anonymous 2007-03-23 13:05 ID:/S/tBbjI

>>7
So, it looks like I'll have to override char *, int, and whatever else I want it to handle automatically. That's fine, but I'm still not sure on how exactly to do it. Sure, I could just pass a stringstream to a function, but then I'd have something like:

oss << "Name: " << getName() << " Age: " << getAge();
addMessage(oss.str());
oss.str("");

That's three lines of code every time I want to add a message, though. Could you be a little more specific about what I need to do, maybe?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List