插入文件好帮手
  • 板块灌水区
  • 楼主XCMG_XCA4000
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/4/16 17:24
  • 上次更新2023/10/23 18:16:06
查看原帖
插入文件好帮手
993194
XCMG_XCA4000楼主2023/4/16 17:24
#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++,一次多文件

2023/4/16 17:24
加载中...