//定义一个vector,用于存储从txt中读取到的数据
vector<string> vStr;
ifstream ifs("文件名",ios::out);//打开文件,设置文件模式为读取模式
//判断是否打开成功
if(ifs.fail())
{
cerr<<"can not open the file";
return;
}
//假设现在读取的均为string类型的数据
while(!ifs.eof())
{
string temp;
ifs>>temp;
vStr.push_back(temp);
}
//向txt中写数据
ofstrem ofs("文件名",ios::app);//打开文件并设置为追加模式
vector<int> data(100,0);//假设每行有100位数
for(int i=0;i<100;i++)//假设有100行
{
copy(data,data+100,ostream_iterator<int>(ofs,"\n"));//往里面追加数据
}
温馨提示:答案为网友推荐,仅供参考