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 2:45 ID:5vQRFgWt

use stringstreams


#include <sstream>

std::ostringstream strout;
strout << "Name: " << getName() << " Age: " << getAge();
foo(strout.str().c_str());

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