for (int i - 0; i < 10; ++i) {
char filePath[100] = "./";
char index[1] = { 0 };
sprintf(index, "%d", i);
strcat(filePath, index);
strcat(filePath, ".txt");
ofstream f(filePath);
f << data << endl;
}
以循环中index作为名称创建文件并保存数据
最新推荐文章于 2023-12-28 10:40:37 发布
这段代码用于在当前目录下批量创建从0到9的文本文件,并将特定数据写入每个文件中。它使用了C++的文件操作函数,如`ofstream`,结合字符串操作如`sprintf`和`strcat`来构建文件路径。
2038

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



