文件操作

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#define int long long
#define O(x) cout<<#x<<" "<<x<<endl;
#define B cout<<"Breakpoint"<<endl;
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a;
}
struct node{
	int x;
	char a[100];
};
set<string> s;
signed main(){
	FILE *fp = 0,*tmpfp;
	if ((fp = fopen("C:\\Users\\Lenovo\\Desktop\\1.txt","w+")) == 0){
		return 0;
	}
	if ((tmpfp = fopen("C:\\Users\\Lenovo\\Desktop\\1.cpp","w+")) == 0){
		return 0;
	}
	node p;
	while (1){
		if ((fread(&p,sizeof(struct node),1,fp)) == 0) break;
		s.insert(p.a);
	}
	for (auto it = s.begin();it != s.end();it++){
		fprintf(tmpfp,"%s\n",(*it).c_str());
	}
} 
posted @ 2023-03-23 12:50  小又又yyyy  阅读(15)  评论(0编辑  收藏  举报