// 1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <string> #include <iostream> using namespace std; struct conformation { char title[1024]; char content[1024]; char author[20]; char time[20]; }; int main(int argc, char* argv[]) { conformation file; /* int flg; system("mode con cols=60 lines=15&color 2f"); system("cls"); cout<<"\n\n\n\n\n"<<endl; cout<<"\t\t\t1.添加信息"<<endl; cout<<"\t\t\t2.删除信息"<<endl; cout<<"\t\t\t3.改变信息"<<endl; cout<<"\t\t\t4.查看信息"<<endl; cout<<"\t\t\t5.退出系统"<<endl; cout<<endl<<"\t\t\t请选择:"; cin>>flg; system("cls");*/ cout<<"请输入标题:"<<endl; cin>>file.title; cout<<"请输入内容:"<<endl; cin>>file.content; cout<<"请输入时间:"<<endl; cin>>file.time; cout<<"请输入作者:"<<endl; cin>>file.author; FILE *fp; char filename[20]; cout<<"请输入文件名称:"<<endl; cin>>filename; fp=fopen(filename,"wt"); if(fp==NULL) printf("Cannot not open the file!\n"); fprintf(fp,"标题:"); fprintf(fp,"%s",file.title); fprintf(fp,"\n"); fprintf(fp,"内容:"); fprintf(fp,"%s",file.content); fprintf(fp,"\n"); fprintf(fp,"时间:"); fprintf(fp,"%s",file.time); fprintf(fp,"\n"); fprintf(fp,"作者:"); fprintf(fp,"%s",file.author); fclose(fp); //system("cls"); conformation file1; cout<<"请输入文件名称:"<<endl; cin>>filename; fp=fopen(filename,"rt"); if(fp==NULL) printf("Cannot not open the file!\n"); char a[5][10]; fscanf(fp,"%s",&a[0]); fscanf(fp,"%s",&file1.title); fscanf(fp,"%s",&a[1]); fscanf(fp,"%s",&file1.content); fscanf(fp,"%s",&a[2]); fscanf(fp,"%s",&file1.time); fscanf(fp,"%s",&a[3]); fscanf(fp,"%s",&file1.author); fclose(fp); printf("%s",a[0]); printf("%s",file1.title); printf("%s",a[1]); printf("%s",file1.content); printf("%s",a[2]); printf("%s",file1.time); printf("%s",a[3]); printf("%s",file1.author); return 0; }