istringstream
単純な文字列を一連の整数に分割するために使用しようとしています。
#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;
}
}
そして私は得る:
* 1
* 2
* 3
* 3
最後の要素が常に2回出てくるのはなぜですか?それを修正する方法は?