sstream

Why is stringstreams rdbuf() and str() giving me different output?

I have this code, int main() { std::string st; std::stringstream ss; ss<<"hej hej med dig"<<std::endl; std::getline(ss,st,' '); std::cout <<"ss.rdbuf()->str() : " << ss.rdbuf()->str(); std::cout <<"ss.rdbuf() : " << ss.rdbuf(); return 0; } Giving me this output ss.rdbuf()->str() : hej hej med dig ...

Have a C++ Class act like a custom ostream, sstream

I have a C++ class MyObject and I want to be able to feed this data like I would to a osstream (but unlike a direct sstream, have the incoming data be formatted a special way). I can't seem to figure out how to overload a operator for MyObject to eat input given to it. class MyObject { public: ostringstream s; FEEDME }; int m...

C++ stringstream returning extra character?

I've been attempting to use the C++ stringstream class to do some relatively simple string manipulations, but I'm having a problem with the get() method. For some reason whenever I extract the output character by character it appends a second copy of the final letter. #include <iostream> #include <sstream> #include <string> using namesp...

sstream not working...(STILL)

I am trying to get a double to be a string through stringstream, but it is not working. std::string MatlabPlotter::getTimeVector( unsigned int xvector_size, double ts ){ std::string tv; ostringstream ss; ss << "0:" << ts << ":" << xvector_size; std::cout << ss.str() << std::endl; return ss.str(); } It outputs only...

How to parse complex string with C++ ?

I'm trying to figure out how could I parse this string using "sstream" and C++ The format of it is: "string,int,int". I need to be able to assign the first part of the string which contains an IP address to a std::string. Here is an example of this string: std::string("127.0.0.1,12,324"); I would then need to obtain string someSt...

Passing unknown classes to String Streams in C++

I am using a template function and I am passing and I may be sending instances of a variety of classes to a string stream. What can I do to make sure this continues to work? Let me be more specific where do I define the behavior for this? Is there some member that should be on each class being sent to the string stream, should I in some...

parsing an sstream

Hi, I am parsing a file which contains both strings and numerical values. I'd like to process the file field by field, each delimited by a space or an end-of-line character. The ifstream::getline() operation only allows a single delimiting character. What I currently do is thus a getline with the character ' ' as a delimiter, and then m...