I get an off by one error while executing the following code
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main (int argc, char* argv[]){
string tokens,input;
input = "how are you";
istringstream iss (input , istringstream::in);
while(iss){
iss >> tokens;
cout << tokens << endl;
}
return 0;
}
It prints out the last token "you" twice, However if I make the following changes everything works fine.
while(iss >> tokens){
cout << tokens << endl;
}
Can anyone explain me how is the while loop operating. Thanks