C++循环读取文件中的每一行数据
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
int main(){
ifstream in("C:\...\filelist.txt");
if(!in){
cerr << "Can't open the file." << endl;
return -1;
}
string line;
vector<string> words;
while(getline(in,line))
words.push_back(line);
in.close();
vector<string>::const_iterator data = words.cbegin();
while (data != words.cend()){
//在这个循环里,可以对每一个data进行操作
cout << *data << endl;
++it;
}
return 0;
}
参考:https://www.cnblogs.com/dingxiaoqiang/p/6511642.html