#include<iostream>
#include<vector>
#include<string>
#include<fstream>
using namespace std; int main()
{
ifstream in("test.txt");
if (!in)
{
cerr << "打开文件失败" << endl;
exit();
} vector<string> vec;
string str;
in >> str;
while (getline(in, str))
vec.push_back(str); for (auto c : vec)
cout << c << endl;
return ;
}
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
using namespace std; int main()
{
ifstream in("test.txt");
if (!in)
{
cerr << "打开文件失败" << endl;
exit();
} vector<string> vec;
string str;
in >> str;
while (getline(in, str))
vec.push_back(str); for (auto c : vec)
cout << c << endl;
return ;
}
test.txt文件内容:
输出结果: