#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
//8.9
//8.10
int main()
{
vector<string> files;
string fileName = "fileList.txt";
fstream f; //可读写
f.open(fileName);
if(!f) //打开失败
{
cout <<"Sorry! open file failed!" << endl;
return 0;
}
char name[1024]; //
while(cin.get(name,1024,'\n'),!cin.eof()) //输入
{
f << name << '\n'; //输入到文件
fflush(stdin); //清除流里面的回车
}
f.clear(); //清除流
f.close(); //关闭文件 这样写入的文件才能生效 一遍后面读到vector
f.open(fileName); //再次打开来读
char chs[1024];
while(f.getline(chs,1024))
{
//cout << chs << endl;
files.push_back(chs);
}
f.clear();
f.close();
for(vector<string>::iterator iter = files.begin(); iter < files.end(); iter ++) //遍历vector 容器
{
cout << *iter;
}
system("pause");
return 0;
}