【发布时间】:2012-02-17 11:28:31
【问题描述】:
在执行以下代码时,我得到了一个错误
#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;
}
它会打印出最后一个标记“你”两次,但是如果我进行以下更改,一切正常。
while(iss >> tokens){
cout << tokens << endl;
}
谁能解释一下while循环是如何运作的。谢谢
【问题讨论】:
标签: c++ istringstream