当我运行这段代码时:
for (int i = 0; i < indexArray.size(); i++) {
iss.str(indexArray.at(i));
iss>>one;
iss>>two;
iss>>three;
cout<<one<<" "<<two<<" "<<" "<<three<<" "<<"\n";
}istreamstream (iss)在每次迭代中都保持不变。(该文件在程序开始时被读取到向量中。是的,我检查了以确保数组有相应的数据。)
换句话说,我得到了这个输出:
12345 1 0
12345 1 0
12345 1 0 而文件/向量实际上是这样写的:
12345 1 0
12346 1 25
12543 1 50我试过各种线索,但找不到问题。谢谢!
发布于 2015-05-31 04:16:18
在重用iss.clear();时,应该在iss.str(indexArray.at(i));之前调用istringstream来清除istringstream标志。
https://stackoverflow.com/questions/30553774
复制相似问题