#include <iostream>
#include <stdio.h>
#include <fstream>
#include <windows.h>
#define name_space 14
#define data_space 4
#define difination(type,name,value) type name[value+1];\
name[value]=0;\
int count=0;\
for(count=0;name[count];count++){name[count]=0;}
class txt;
using namespace std;
struct character
{
char option_name[50];
void(txt::*fc)();
};
class txt
{
public:
txt(int i);
void txt_file();
void txt_write();
void txt_output();
void select();
void procees();
private:
int option_total;
character * option;
char path[50];
public:
int judge;
};
void txt::txt_file()
{
cout<<"txt_file"<<endl;
char * name=new char [name_space];
ofstream newfile;
newfile.open(path,ios::ate);
cout<<"请输入标题"<<endl;
scanf("%s",name);//cin>>name;
newfile<<name<<endl;
newfile.close();
system("pause");
}
void txt::txt_write()
{
cout<<"txt_write"<<endl;
}
void txt::txt_output()
{
system("cls");
cout<<"txt_output"<<endl;
ifstream newfile;
//char * article = new char [2][50];//1=title ,2=text
char * title=new char[50];
char data[20][50];
int count_1,count_2;
count_1=count_2=0;
newfile.open(path,ios::in);
//while(newfile.get(title[count])&&(title[count]!='\n'))//input title
while(newfile.get(data[count_2][count_1]))
{
if(data[count_2][count_1]=='\n')
{
count_2++;
count_1=0;
continue;
}
count_1++;
}
data[count_2][count_1]='\0';
count_2=0;
count_1=0;
//cout<<setw(data_space);
while(data[count_2][count_1])
{
cout<<data[count_2][count_1];
if(data[count_2][count_1]=='\n')
{
count_2++;
count_1=0;
continue;
}
// cout<<data[count_2][count_1];
count_1++;
}
//cout<<"file_output"<<endl<<setw(name_space)<<title<<endl;
delete(title);
cout<<endl;
system("pause");
newfile.close();
}
void txt::select()
{
while(1)
{
int temp=0;
cout<<"select"<<endl;
character option_array[option_total]={character{"1、新建文件",&txt::txt_file},character{"2、文件尾写入文本",&txt::procees},character{"3、文件打印",&txt::txt_output}};
option=option_array;
difination(int,option_count,1);
for(;option_count[0]<option_total;option_count[0]++)
{
cout<<option_array[option_count[0]].option_name<<endl;
}
cin>>temp;
txt * a=new txt(1);
(a->*(option[temp-1].fc))();
delete(a);
}
}
void txt::procees()
{
int count_2,count_1;
char * temp=new char[100];
char data [20][100];
count_1=0;
count_2=0;
printf("请在下面输入:");
scanf("%c",temp);//string conversion to characters @@@@@
while((data[count_2][count_1]=getchar())!='\n')//getchar: from stream get characters @@@@@@
{
// printf("%c",data[count_2][count_1]);
if(data[count_2][count_1]==' ')
{
data[count_2][count_1]='\n';
count_2++;
count_1=0;
continue;
}
// cout<<data[count_2][count_1]<<endl;
count_1++;
//cout<<2<<endl;
}
int number=count_2+1;
ofstream file;
file.open(path,ios::app);
data[count_2][count_1]='\0';
count_2=0;
count_1=0;
//file<<setw(data_space);
while(data[count_2][count_1])
{
file<<data[count_2][count_1];
if(data[count_2][count_1]=='\n')
{/*
if((count_2+1)%3==0)//@@
file<<endl<<setw(data_space);
else
file<<setw(data_space);*/
count_1=0;
count_2++;
continue;
}
count_1++;
}
file.close();
system("pause");
count_2=0;//debug
count_1=0;
/*while(((data[count_2][0]=='e')&&(count_2==number))==0)//@@@@@@ 'e' is only one to the end ,count_2==number is in order to tp make'e' unique//fuck?? while((((data[count_2][0]!='e')==0)&&((count_2!=number)==0))==0)
{
cout<<data[count_2][count_1];
if(data[count_2][count_1]=='\n')
{
count_1=0;
count_2++;
continue;
}
count_1++;
}*///与是或的子集
//cout<<"个数为:"<<count_2;
delete(temp);
}
txt::txt(int ii):option_total(3),option(0),judge(ii),path("D:\\file/fist.txt")
{
cout<<"initialize"<<endl;
if(judge==0)
select();
else
{
}
}
int main()
{
txt fist(0);
return 0;
}