I'm trying to use istringstream
to split a simple string into a series of integers:
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(){
string s = "1 2 3";
istringstream iss(s);
while (iss)
{
int n;
iss >> n;
cout << "* " << n << endl;
}
}
And i get:
* 1
* 2
* 3
* 3
Why is the last element always coming out twice? How to fix it?