Converting ostream into standard string
The question was on ostream
to string, not ostringstream
to string.
For those interested in having the actual question answered (specific to ostream
), try this:
void someFunc(std::ostream out)
{
std::stringstream ss;
ss << out.rdbuf();
std::string myString = ss.str();
}
std::ostringstream stream;
stream << "Some Text";
std::string str = stream.str();
const char* chr = str.c_str();
And I explain what's going on in the answer to this question, which I wrote not an hour ago.
Try std::ostringstream
std::ostringstream os;
os<<"Hello world";
std::string s=os.str();
const char *p = s.c_str();