文件流代码

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv) {
//	char data[100];
//	ofstream out;
//	out.open("lll.txt");
//	cin.getline(data,100);
//	out<<data<<endl;
//	out.close();
//	
//	ifstream in;
//	in.open("lll.txt");
//	in>>data;
//	in.close();
//	cout<<data;
	
	char data[100];
	ofstream on;
	ifstream in;
	cin.getline(data,100);
	for(int i=0;i<10;i++){
		on.open("lll"+to_string(i)+".txt",ios::trunc);
		on<<data<<endl;
		on.close();
		
		in.open("lll"+to_string(i)+".txt");
		in>>data;
		in.close();
		cout<<data<<endl;
		
		
	}
	
	
	
	return 0;
}

  

posted @ 2023-11-03 20:03  王ys  阅读(10)  评论(0)    收藏  举报