#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() {
ifstream ifs;
ifs.open("文件名称.txt", ios::in);
if (!ifs.is_open()) {
cout << "文件打开失败" << endl;
return 0;
}
string a[1000];
int i;
string buf;
for (i = 0; getline(ifs, buf); i++)
a[i] = buf + ".txt";
ofstream ofs;
for (int j = 0; j < i; j++) {
ofs.open(a[j], ios::out);
ofs << "/*" << endl;
ofs << "*/" << endl;
ofs << endl;
ofs.close();
cout << a[j] << "创建成功!" << endl;
}
return 0;
}
【C++】用C++批量创建txt文件
最新推荐文章于 2025-11-24 17:31:05 发布
本文介绍了一个使用 C++ 编写的程序,该程序能够从一个源文件中读取每一行的内容,并为每一行内容创建一个对应的 .txt 文件。在每个新建的文件中,程序会自动写入简单的注释。此方法适用于需要快速生成多个带有预设内容文件的场景。
2894

被折叠的 条评论
为什么被折叠?



