08 IO库

时间:2023-03-09 04:07:33
08 IO库
 #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文件内容:

08 IO库

输出结果: