直接贴代码:
#include <iostream>
#include <fstream>
#define MAXN 100 //生成测试文件的数量
using namespace std;
int main()
{
int index=1;
char namebuffer[248];
while(index<=MAXN)
{
//sprintf(namebuffer,"d:\\txt\\%d.txt",index); //设置保存生成文件的绝对路径
sprintf(namebuffer,"d:\\%d.txt",index); //设置保存生成文件的绝对路径
ofstream ofile(namebuffer);
ofile<<"在文件“index.txt”中应该输出的文字";
index++;
}
return 0;
}