要读取的文件放在.sln的问文件夹下
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
void read_file()
{
ifstream aa;
aa.open("busroute.txt");
vector<string> tt;
string test;
while (getline(aa, test))
{
tt.push_back(test);
}
for (int i = 0; i < tt.size(); i++)
{
cout << tt[i] << endl; //打印数据
}
aa.close();
}
int main()
{
read_file();//按行读取文件中的所有数据
return 0;
}
输入结果