⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.cpp

📁 用JAVA实现的简单编辑器
💻 CPP
字号:
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

//struct Line
//{
//	char ll [300];
//	int num;//行号
//	Line(char l [],int lsize,int n)
//	{
//			for(int i=0;i<lsize;i++)
//			{
//				ll[i]=l[i];
//				if(l[i]=='\0') break;
//			}
//		//ll=l;
//		num=n;
//	}
//	Line(){}
//	friend int operator ==(const Line & L,const Line & T){return L.num==T.num;}
//};

class File
{
public:
	File(){}
	~File(){}
	vector<char *> nl;
	void load(char fn[20])
		{
	ifstream in;
	in.open(fn);
	if(in.fail())
	{
		cout << "opening file failed.\n";
		exit(1);
	}
	int num=0;
	
	while(!in.eof())
	{
		//num++;
		char newll [300];
		in.getline(newll,300);cout << newll << endl;
		//Line newl(newll,300,num);
		//ListItr<Line> itr(this->nl);cout << fn;
		nl.push_back(newll);cout << fn;
		//cout << newll << endl;
	//string temp;
	
	}

	}
	void save(char fn[20])
	{
	ofstream out;
	out.open(fn);
	for(int i=0;i<nl.size();i++)
	{
		//Line l=nl.at(i);
		out << nl.at(i);
	}
	out.close();
}
	void del_letter(const int col,const int row)
		{
	//ListItr<Line> itr(nl);
			/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
		//itr++;
	//Line *temp=itr();
			nl.at(row-1)[col-1]=' ';
	for(int i=col-1;i<299;i++)
	{
		nl.at(row-1)[i]=nl.at(row-1)[i+1];
		if(nl.at(row-1)[i+1]=='\0') break;
	}
}
	void add_letter(const char newl,const int col,const int row)
		{
	/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
	//Line *temp=itr();
	char fb[300];
	for(int x=0;x<300;x++)
	{
		fb[x]=nl.at(row-1)[x];
		if(nl.at(row-1)[x]=='\0') break;
	}
	for(int i=col-1;i<299;i++)
	{
		nl.at(row-1)[i+1]=fb[i];
		if(fb[i]=='\0') break;
	}
	nl.at(row-1)[col-1]=newl;
}
	void replace_letter(const char newl,const int col,const int row)
		{
	/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
	//Line *temp=itr();
			nl.at(row-1)[col-1]=newl;
}
	void del_word(const int col,const int row)
		{
	/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
	//Line *temp=itr();
	int length=0;
	for(int i=col-1;i<300;i++)
	{
		if(nl.at(row-1)[i]==' ') break;
		length++;
	}
	for(int j=col-1;j<300-length;j++)
	{
		nl.at(row-1)[j]=nl.at(row-1)[j+length];
		if(nl.at(row-1)[j+length]=='\0') break;
	}
}
	void add_word(const char word [20],const int col,const int row)
		{
	/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
	//Line *temp=itr();
	int length=0;
	for(int i=0;i<20;i++)
	{
		if(word[i]=='\0')
		{
			length=i;
			break;
		}
	}
	char fb[300];
	for(int x=0;x<300;x++)
	{
		fb[x]=nl.at(row-1)[x];
		if(nl.at(row-1)[x]=='\0') break;
	}
	nl.at(row-1)[col-1]=' ';
	nl.at(row-1)[col+length]=' ';
	for(int m=col-1;m<298-length;m++)
	{
		nl.at(row-1)[m+length+2]=fb[m];
		if(fb[m]=='\0') break;
	}
	int c=col;
	for(int j=0;j<length;j++)
	{
		nl.at(row-1)[c]=word[j];
		c++;
	}
}
	void replace_word(const char word [20],const int col,const int row)
		{
	/*int pos=0;
			for(;pos<nl.size();pos++)
			{
				if(nl.at(pos).num==row) break;
			}*/
	//Line *temp=itr();
	int newlength=0;
	for(int i=0;i<20;i++)
	{
		if(word[i]=='\0')
		{
			newlength=i;
			break;
		}
	}
	int oldlength=0;
	for(int j=col-1;j<300;j++)
	{
		if(nl.at(row-1)[j]==' ') break;
		oldlength++;
	}
	//char fb[300]=temp->ll;
	for(int n=0;n<oldlength;n++)
	{
		nl.at(row-1)[n+col-1]=' ';
	}
	int c=col-1;
	for(int m=0;m<newlength;m++)
	{
		nl.at(row-1)[c]=word[m];
		c++;
	}
}
//	void del_row(const int row)
//		{
//	int pos=0;
//			for(;pos<nl.size();pos++)
//			{
//				if(nl.at(pos).num==row) break;
//			}
//	Line temp=itr();
//	itr.Remove(temp);
//}
//	void add_row(const Line & newline)
//		{
//	ListItr<Line> itr(nl);
//	itr.Insert(newline);
//	int numm=0;
//	for(;itr.hasValue();itr++)
//	{
//		numm++;
//	}
//	//newline.num=numm
//}
//	void replace_row(const Line & newline)
//		{
//	ListItr<Line> itr(nl);
//	int numm=0;
//	for(;itr.hasValue();itr++)
//		numm++;
//	Line temp=itr();
//	itr.Remove(temp);
////	newline.num=numm;
//	itr.Insert(newline);
//}
//private:
	//string file_name;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -