我清空了一个字符串流,然后我尝试再次填充它,但没有成功。我不明白为什么。这是我的代码:
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[] ) {
stringstream ss1, ss2;
ss1 << "0 1 2 3 40 5 6 76 8 9"; // Stream is filled with one string of chars
vector <int> V;
string st;
int number;
while(!ss1.eof() ) {
ss1 >> number; // Next int found in ss1 is passed to number
V.push_back(number);
ss2 << number << " "; // ss2 is filled with number + space in each iteration.
} // Basically here, the content of ss1 has been passed to ss2, leaving ss1 empty.
ss1 << "helloooo";
getline(ss1, st);
cout << st << endl; // <--- Here, st appears to be empty... Why ?
return 0;
}