64,673
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<fstream>
int main()
{
using namespace std;
char theRestoryDirectory[40]="C:\\USers\\gongxinyu\\Desktop\\test\\"; //设置存储路径
char theHeader[10]; //设置需要创建的文件名
cout << "Enter the filename:";
cin >> theHeader;
while(strlen(theHeader)>10) //文件名长度不超过10
{
cout << "The filename is too long!(max is 10 numbers.)" << endl;
cout << "Enter the filename again:";
cin >> theHeader;
}
char theExtension[10]=".txt"; //命名后缀为.txt
char name[100];
int num; //设置需要创建的文件数量
cout << "Enter the quality of documents:";
cin >> num;
ofstream outFile;
for(int i=1;i<=num;i++)
{
sprintf(name,"%s%s%d%s",theRestoryDirectory,theHeader,i,theExtension);
outFile.open(name);
outFile << "<" << theHeader << i << ">" << " contains " << i << " tips:\n" << endl;
for(int j=1;j<=i;j++)
{
outFile << "This is the " << j << " tip of " << theHeader << i << endl;
}
outFile.close();
}
return 0;
}