tags:

views:

30

answers:

2

Hello all,

I am very new to the C++ STL, so this may be trivial. I have a ostream variable with some text in it.

ostream* pout;
(*pout) << "Some Text";

Is there a way to extract the stream and store it in a string of type char*?

+1  A: 
     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.

James Curran
I get the following error message:'struct std::basic_ostream<char, std::char_traits<char> >' has no member named 'str'
freyrs
Include the necessary headers .`#include <string>` and `#include <sstream>`
Prasoon Saurav
+1  A: 

Try std::ostringstream

   std::ostringstream os;
   os<<"Hello world";
   std::string s=os.str();
   char *p = s.c_str();
Prasoon Saurav