RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
C++怎么实现文本编辑器-创新互联

这篇文章主要介绍了C++怎么实现文本编辑器,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

创新互联是专业的赫章网站建设公司,赫章接单;提供网站设计制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行赫章网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

具体内容如下

1.简易文本编辑器

2.用链表实现,保存到文件中

#include
#include
#include
#include
#include
#include
using namespace std;
int NumberCount=0;//数字个数
int CharCount=0;//字母个数
int PunctuationCount=0;//标点符号个数
int BlankCount=0;//空白符个数
 
class Node
{
public:
  string character;
  int cursor;
  int offset;
  Node* next;
  Node(){
    cursor=0;//每行的光标初始位置
    offset=0;//每行的初始偏移位置
    next=NULL;
  }
};
 
class TextEditor
{
private:
  Node* head;
  string name;
  int line;//可更改的行数
  int length;//行数
public:
  TextEditor();
  ~TextEditor();
  string GetName();
  void SetName(string name);
  int GetCursor();
  int MoveCursor(int offset);
  int SetCursor(int line,int offset);
  void AddText(const string s);
  void InsertText(int seat,string s);
  int FindText(string s);
  void DeleteText(string s);
  int GetLine();
  void Count();
  friend ostream& operator<<(ostream& out,TextEditor &text);
  Node* Gethead(){
    return head;
  }
  //int GetLength()
  //{
  //   return length;
  // }
 // int FindText(string s);
 // void DeleteText(int seat,string s);
};
 
TextEditor::TextEditor()
{
  head=NULL;
  name="test";//文件初始名
  //tail=NULL;
  line=1;
  length=0;
}
 
TextEditor::~TextEditor()
{
  Node* p=head;
  Node* q;
  while(p!=NULL){
    q=p->next;
    delete p;
    p=q;
  }
 
}
 
int TextEditor::GetLine()
{
  return line;
}
 
string TextEditor::GetName()
{
  return name;
}
 
void TextEditor::SetName(string name)
{
  this->name=name;
}
 
int TextEditor::GetCursor()
{
  Node *p=head;
  while(p->next!=NULL)
    p=p->next;
  return p->cursor;
}
 
int TextEditor::MoveCursor(int offset)
{
  Node *p=head;
  int i=1;
  if(length+1next!=NULL&&inext;
      i++;
    }
  }
  if(offset>p->character.length()){
    cout<<"移动位置太大!"<cursor+=offset;
  //cout<<"p ->cursor="<cursor<cursor;
}
 
int TextEditor::SetCursor(int line,int offset)
{
  this->line=line;
  //cout<<"line="<line<character=s;
  p->next=NULL;
  if(head==NULL)
    head=p;
  else{
    while(q->next!=NULL)
      q=q->next;
    q->next=p;
  }
 
    length++;
    // line++;
}
 
void TextEditor::InsertText(int seat,string s)
{
  Node *p=head;
  int i=1;
  if(length+1next!=NULL&&inext;
      i++;
    }
  }
  //MoveCursor(seat);
  //cout<<"p->cursor="<cursor<character.length();i++)
  substr+=p->character[i];
 
  p->character.insert(p->cursor,s);
 
 
  cout<<"substr="<cursor=0;//光标清零
}
 
ostream& operator<<(ostream& out,TextEditor &text)
{
  int i=1;
  Node* p=text.Gethead();
  while(p!=NULL){
    out<character<next;
  }
  // cout<<"length="<next;
      // cout<character<character.erase(k-1,s.length());
    cout<<"删除成功!"<character.length();i++){
        if(p->character[i]>='0'&&p->character[i]<='9')
          NumberCount++;
        else if(p->character[i]>'a'&&p->character[i]<'z'||p->character[i]>'A'&&p->character[i]<'Z')
          CharCount++;
        else if(ispunct(p->character[i]))
          PunctuationCount++;
        else if(p->character[i]==' ')
          BlankCount++;
      }
      p=p->next;
  }
}
 
int main()
{
  int i,j,k,n=2;
  string s,t,name;
  TextEditor text;
  cout<<"---------------------------------------"<>n;
    getchar();
    switch(n){
      case 1: cout<<"请输入字符:"; getline(cin,s,'\n'); text.AddText(s); break;
      case 2: cout<<"请输入文档名字:"; cin>>name; text.SetName(name); break;
      case 3: cout<>i;
        cout<<"光标在第"<>j;
        cout<<"输入插入字符:";
        getchar();
        getline(cin,s);
        text.InsertText(text.SetCursor(i,j),s); break;
      }
      case 6: {
        cout<<"输入查找的字符串:";
        getline(cin,s);
        int k=text.FindText(s);
        if(k==-1)
          cout<<"查找失败!"<character<next;
        }
        exit(0);
        break;
      }
      default: cout<<"输入错误,请重新输入!"<

感谢你能够认真阅读完这篇文章,希望小编分享的“C++怎么实现文本编辑器”这篇文章对大家有帮助,同时也希望大家多多支持创新互联建站,关注创新互联网站建设公司行业资讯频道,更多相关知识等着你来学习!

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:C++怎么实现文本编辑器-创新互联
本文URL:http://sczitong.cn/article/cdpecd.html