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

📄 test.cpp

📁 数据库的代码 数据库 的代码 数据库的代码
💻 CPP
字号:
#include "String.h"

void InPut(char *p);
void InputChar(char *p);
void ShowMenu();

int main()
{
	String<char>  str;
	ShowMenu();                 //显示菜单
	int choice;
	while(true)
	{
		cout<<"\nPlease input your option:  ";
		cin>>choice;
		switch(choice)
		{
		case 1:
			{
				cout<<"Please input your context in the consel\n";
				char a[100];					 //定义一个数组变量
				InPut(a);						//输入数组	
				str.Input(a);
//				cout<<str<<endl;
				break;
			}
		case 2:
			try
			{
				cout<<"Please input the suffix / length\n";
				int suffix,length;
				cin>>suffix>>length;
				str.Delete(suffix,length);
			}
			catch(char *p)
			{
				cout<<p<<endl;
			}
			break;
		case 3:
			//		str.StrPrint();
			cout<<str;
			break;
		case 4:
			{
				char *p = "INSERT";
				String<char> insertLine(p);
				int Line;
				cout<<"Please input the Line\n";
				cin>>Line;
				str.InsertBeforeLine(Line,insertLine);
				break;
			}
		case 5:
			{	
				char *p = "INSERT";
				String<char> insertLine(p);
				int Line;
				cout<<"Please input the Line\n";
				cin>>Line;
				str.InsertAfterLine(Line,insertLine);
				break;
			}
		case 6:
			{
				int line;
				cout<<"Please input the line you want to delete: ";
				cin>>line;
				str.Delete(line);
				break;
			}
		case 7:
			{
				int Line,Begin,Len;
				cout<<"Please input the LineNum/Begin/Length\n";
				cin>>Line>>Begin>>Len;
				str.DeleteInLine(Line,Begin,Len);
				break;
			}
		case 8:
			{
				cout<<"Please input the Line/Begin"<<endl;
				int Line,Begin;
				char *p = "INSERT";
				cin>>Line>>Begin;
				str.InsertInLine(Line,Begin,String<char>(p));
				break;
			}
		case 9:
			{
				cout<<"Please input the string you want to find\n";
				char p[100];
				InputChar(p);
				cout<<"Please input the string you want to replace\n";
				char q[10];
				InputChar(q);
				
//				while(str.FindAndReplace(String<char>(p),String<char>(q)));
				str.FindAndReplace(String<char>(p),String<char>(q));
				break;
			}
		case 10:
			{
				char *FileName = "aaa.txt";
				str.SaveToFile(FileName);
				break;
			}
			
		case 11:
			{
				char *FileName = "aaa.txt";
				str.ReadFromFile(FileName);
				break;
			}
		default:
			break;
		}
	}

	return 0;
}


void InPut(char *p)
{
	char ch;
	int i = 0;
	int EnterNum = 0;
	ch = getchar();
	do 
	{
		ch = getchar();
		if(ch == 10)
			EnterNum ++;
		p[i ++] = ch;
	} 
	while(EnterNum < 8);
	p[i - 1] = '\0';
}


void InputChar(char *p)
{
	char ch;
	int i = 0;
	do 
	{
		cin>>p;
		ch = getchar();
	}
	while(ch != 10);
	p[i - 2] = '\0';
}

void ShowMenu()
{
	cout<<"1------construct a String object\n"
		<<"2------Delete a substring\n"
		<<"3------Print the String on screen\n"
		<<"4------Insert a line before one line\n"
		<<"5------Insert a line after one line\n"
		<<"6------Delete a line\n"
		<<"7------Delete a substring in one line\n"
		<<"8------Insert a subsgring in one line\n"
		<<"9------Find and Replace\n"
		<<"10-----Save to File\n"
		<<"11-----Read from the File\n";
}

⌨️ 快捷键说明

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