0

当我运行此代码时:

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

我尝试了各种痕迹,无法查明问题所在。谢谢!

4

1 回答 1

1

重用时,您应该调用iss.clear();beforeiss.str(indexArray.at(i));清除 EOF 标志istringstream

于 2015-05-31T04:16:18.243 回答