1

I'm fightning with a map loading bug in my engine, and finally I found it. However, it seems it's something wrong with stringstream and getline... Minimal code:

#include <string> #include <iostream> #include <sstream> int main(int argc, char **argv) { std::string text = "1!2!6|6|5|"; std::stringstream buffer; buffer << text; // insert to buffer std::string temp; buffer >> temp; // extract buffer << temp; // then insert again (i need it in my code to count characters) // and I can't count it before, as in my code the buffer is filled from file std::string loaded; std::getline(buffer, loaded, '!'); //should instert "1" to loaded std::cout << loaded; //and it displays nothing, debugger shows loaded is empty } 

Am I doing something wrong or is it a bug? I'm using g++ 4.7 c++11.

1 Answer 1

4

For extracting the string from stringstream in this case, you probably want:

temp = buffer.str(); 

instead of:

buffer >> temp; 

See: extracting formatted (interpreted) data vs. stringstream.str()

Sign up to request clarification or add additional context in comments.

1 Comment

It works! Thanks a lot. I'll accept your answer when it will be possible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.