64,654
社区成员
发帖
与我相关
我的任务
分享
这样貌似要好一点
fin >> n;
vec.resize(n);
for (i = 0; i < n; ++i)
fin >> vec[i];
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
fstream file;
file.open("filename.txt");// 把你数据保存在filename.txt 文件里面
if(!file.is_open())
{
cout<<"file fail!"<<endl;
return 1;
}
string str;
vector<string> v;// 数组里面
while(file>>str)
{
v.push_back(str);
}
for(unsigned int i=0;i<v.size();i++)
{
cout<<v.at(i)<<endl;
}
file.close();
file.clear();
return 1;
}