直接贴代码:
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> files;
for (int i = 0; i < 10; i++)
{
stringstream str;
str << i;
files.push_back(str.str());
}
ofstream outfile;
outfile.open("files1.txt", ios_base::out | ios_base::trunc); //删除文件重写
for (int i = 0; i < files.size(); i++)
{
stringstream ss;
ss << files[i];
outfile << ss.str() << endl;
}
outfile.close();
return 0;
}
语法链接: