0

Possible Duplicate:
C++ - repeatedly using istringstream

Given this code :

   string line;  // for the line
   ifstream myfile ("input.txt");
   int algorithmNumber , matrixDim;
   getline (myfile,line);
   istringstream buffer(line);
   buffer >> algorithmNumber;

I read one line and then convert that line from string to int .

But if I want to read the next line and do that again :

   buffer(line);
   buffer >> matrixDim;

I get this : no match for call to '(std::istringstream {aka std::basic_istringstream<char>}) (std::string&)'

How can I read the next line and convert it into int with istringstream ?

Regards

Community
  • 1
  • 1
JAN
  • 21,236
  • 66
  • 181
  • 318
  • Why not just create a new `istringstream` object? – hmjd Nov 21 '12 at 14:15
  • taht's not the answer, the correct answer is to use str(). You also have to clear any flags that were set whilst parsing the previous string. – CashCow Nov 21 '12 at 14:58

0 Answers0