D
David Olsson
Hello!
I have a little problem with one of the get methods of the
stringstream class. Consider the code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
string all_names = "David Olsson, Bengt Bengtsson, Kalle von Sydow";
stringstream ns(all_names);
stringbuf name_buf;
while(ns.get(name_buf, ',')) {
string name = name_buf.str();
cout << name << endl;
}
return(EXIT_SUCCESS);
}
I would expect this code to produce the following output:
David Olsson
Bengt Bengtsson
Kalle von Sydow
However, the real output is as follows:
David Olsson
The problem is thus that the second call to ns.get(...) fails, even
though there still should be characters to read.
Am I using the stringstream class in an appropriate way? Very grateful
for any suggestions!
David Olsson
I have a little problem with one of the get methods of the
stringstream class. Consider the code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
string all_names = "David Olsson, Bengt Bengtsson, Kalle von Sydow";
stringstream ns(all_names);
stringbuf name_buf;
while(ns.get(name_buf, ',')) {
string name = name_buf.str();
cout << name << endl;
}
return(EXIT_SUCCESS);
}
I would expect this code to produce the following output:
David Olsson
Bengt Bengtsson
Kalle von Sydow
However, the real output is as follows:
David Olsson
The problem is thus that the second call to ns.get(...) fails, even
though there still should be characters to read.
Am I using the stringstream class in an appropriate way? Very grateful
for any suggestions!
David Olsson