#include<bits/stdc++.h>
using namespace std;
string a,b,c,h,ch;
int ci,ci2;
int main()
{
while(10>9)
{
ifstream fin;
ofstream fout;
cout<<"请确认是否替换或写入文件!(yes or no)"<<endl;
cin>>ch;
if(ch=="yes" or ch=="YES" or ch=="Yes")
{
cout<<"文件名:";
cin>>a;
cout<<"后缀名(不带点):";
cin>>h;
c=a+"."+h;
cout<<"行数:";
cin>>ci;
fout.open(c);
for(int i=1;i<=ci;i++)
{
cout<<"第"<<i<<"行"<<endl;
cout<<"单词数(空格数+1):";
cin>>ci2;
cout<<"内容:";
for(int j=1;j<=ci2;j++)
{
cin>>b;
fout<<b<<" ";
}
fout<<endl;
}
fin.close();
fout.close();
}
if(ch=="no" or ch=="NO" or ch=="No")
{
cout<<"退出中..." <<endl<<"退出成功!"<<endl;
fin.close();
fout.close();
break;
}
if(ch!="yes" and ch!="YES" and ch!="Yes" and ch!="no" and ch!="NO" and ch!="No")
{
cout<<"ERROR!"<<endl;
}
}
system("pause");
return 0;
}
代码复制过去,C++,一次多文件