📄 notepad.cpp
字号:
// notepad.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;
#include "File.cpp"
void menu_print1();
void menu_print2();
void control();
void del();
void insert();
void replace();
File * f;
void menu_print1()
{
cout << "1 打开文件\n";
cout << "2 保存文件\n";
cout << "3 删除\n";
cout << "4 插入\n";
cout << "5 更改\n";
cout << "6 复制\n";
cout << "7 粘贴\n";
cout << "8 退出\n";
}
void menu_print2()
{
cout << "2 保存文件\n";
cout << "3 删除操作\n";
cout << "4 插入操作\n";
cout << "5 更改操作\n";
cout << "6 复制\n";
cout << "7 粘贴\n";
cout << "8 退出\n";
}
void control()
{
int com;
do
{
cin >> com;
}while(com<1||com>8);
switch(com)
{
case 1:
{
char fn[20];
cout << "Please enter the name of the file you want to open.\n";
cin >> fn;
f->load(fn);
menu_print2();
break;
}
case 2:
{
char fn[20];
cout << "Please enter the name of the file you want to save.\n";
cin >> fn;
f->save(fn);
menu_print1();
break;
}
case 3:
{
del();
break;
}
case 4:
{
insert();
break;
}
case 5:
{
replace();
break;
}
case 6:
{
break;
}
case 7:
{
break;
}
case 8:
{
break;
}
}
}
void del()
{
cout << "1 删除指定行列字符\n";
cout << "2 删除指定行列开始的单词\n";
cout << "3 删除行\n";
cout << "4 返回\n";
int com;
do
{
cin >> com;
}while(com<1||com>4);
switch(com)
{
case 1:
{
int col,row;
cout << "Please enter the colum and row.\n";
cin >> col >> row;
f->del_letter(col,row);
break;
}
case 2:
{
int col,row;
cout << "Please enter the colum and row.\n";
cin >> col >> row;
f->del_word(col,row);
break;
}
case 3:
{
int row;
cout << "Please enter the row.\n";
cin >> row;
//f->del_row(row);
break;
}
case 4:
{
menu_print1();
break;
}
}
}
void insert()
{
cout << "1 插入字符\n";
cout << "2 插入单词\n";
cout << "3 插入行\n";
cout << "4 返回\n";
int com;
do
{
cin >> com;
}while(com<1||com>4);
switch(com)
{
case 1:
{
char newchar;
int col,row;
cout << "Please enter the letter you want to insert and the colum and row.\n";
cin >> newchar;
cin >> col >> row;
f->add_letter(newchar,col,row);
break;
}
case 2:
{
char word[20];
int col,row;
cout << "Please enter the word you want to insert and the colum and row.\n";
cin >> word;
cin >> col >> row;
f->add_word(word,col,row);
break;
}
case 3:
{
//ListItr<Line> itr(f->nl);
char newl[300];
int numm=f->nl.size()-1;
//for(;itr.hasValue();itr++)
// numm++;
cout << "Please enter the line you want to insert.\n";
cin.getline(newl,300);
numm++;
//Line newline(newl,numm);
//f->add_row(newline);
f->nl.push_back(newl);
break;
}
case 4:
{
menu_print1();
break;
}
}
}
void replace()
{
cout << "1 更改字符\n";
cout << "2 更改单词\n";
cout << "3 更改行\n";
cout << "4 返回\n";
int com;
do
{
cin >> com;
}while(com<1||com>4);
switch(com)
{
case 1:
{
int col,row;
char newchar;
cout << "Please enter the letter you want to replace and the colum and row.\n";
cin >> newchar;
cin >> col >> row;
f->replace_letter(newchar,col,row);
break;
}
case 2:
{
int col,row;
char word [20];
cout << "Please enter the word you want to replace and the colum and row.\n";
cin >> word;
cin >> col >> row;
f->replace_word(word,col,row);
break;
}
case 3:
{
char newl [300];
int numm=f->nl.size()-1;
//ListItr<Line> itr(f->nl);
//for(;itr.hasValue();itr++)
// numm++;
cout << "Please enter the line you want to replace.\n";
cin.getline(newl,300);
//Line newline(newl,numm);
//f->replace_row(newline);
}
case 4:
{
menu_print1();
break;
}
}
}
int main()
{
menu_print1();
control();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -