www.pudn.com > Editor.rar > Edit.cpp


#include"Edit.h" 
 
Editor::Editor(char*  in,char* out) 
{ 
/* 
构造函数,完成初始化操作 
*/ 
	this->in=in; 
	this->out=out; 
	is_inserting=true; 
	current_line=0; 
	infile.open(in); 
	//if(infile==0){ 
	//	cout<<"Can't open input file "<8){				//也许是$Delete命令 
						string str=s.substr(2,6); 
						string st="elete "; 
						if(!str_equal(str,st)){ 
							cout<<"Error:This is not a command!"<6){ 
					string str=s.substr(2,4); 
					string st="ine "; 
					if(!str_equal(str,st)){ 
						cout<<"Error:This is not a command!"<size){ 
						cout<<"Error:The line is not exist!"<7){ 
					string str=s.substr(2,5); 
					string st="rint "; 
					if(!str_equal(str,st)){ 
						cout<<"Error:This is not a command!"<size){ 
		cout<<"Error:The size is smaller than "<*temp=front; 
	int i; 
	for(i=1;inext; 
	} 
	for(;isize){ 
			cout<<"Warning:Line "<data<next; 
	} 
	return; 
} 
 
void Editor::quit() 
{ 
/* 
退出并保存 
*/ 
	infile.close(); 
	cout<<"Do you want to save the text before quiting ? y/n "; 
	if(cin.get()==tolower('y'))save(); 
	cin.get(); 
	return; 
} 
 
bool Editor::str_to_int(string s,int a[],int n) 
{ 
/* 
将字符串s中的数字提取出来,放到数组a中,n为数字的个数 
当不满足提取要求时,返回false 
*/ 
	int size=s.size(); 
	int i=0; 
	int j=0; 
	int c=0; 
	for(j=0;j57)return false; 
			a[j]=a[j]*10+s[i]-48; 
			i++; 
		} 
		i++; 
	} 
	if(c!=n)return false; 
	return true; 
} 
 
void Editor::Print() 
{ 
/* 
重载打印函数,用">"指向当前行 
*/ 
	int i=0; 
	Node*temp=front; 
	while(temp!=NULL){ 
		i++; 
		if(i==current_line)cout<<">"; 
		else cout<<" "; 
		cout<data<next; 
	} 
} 
 
void Editor::save() 
{ 
/* 
将文件存盘,存盘不成功时(比如文件不存在)返回false 
*/ 
	outfile.open(out,ios::trunc); 
	//if(outfile==0){ 
	//	cout<<"Can't open output file "<*temp=front; 
	while(temp!=NULL){ 
		outfile<data<next; 
	} 
	outfile.close(); 
	return; 
} 
 
void Editor::open() 
{ 
	cout<<"Do you want to quit the old text file and open a new one ? y/n "; 
	if(cin.get()==tolower('y')){ 
		quit(); 
		delete in; 
		in=new char[20]; 
		cout<<"Please input the filename to edit:"; 
		cin>>in; 
		is_inserting=true; 
		current_line=0; 
		infile.open(in); 
		//if(infile==0){ 
		//	cout<<"Can't open input file "<