C++ 如何用C++编写一个文本编辑器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1520022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:15:35  来源:igfitidea点击:

how to write a text editor in c++

c++

提问by Haiyuan Zhang

I learned c++ on and off for several times but never write a real apps using it . long time I've been thinking that writing a text editor will be something very interesting , now I am looking for a simple but decent text editor written in c or c++ from which I can get inspiration and learn how to write a text editor by myself.

我断断续续地学习了几次 c++,但从未使用它编写过真正的应用程序。很长一段时间我一直认为编写文本编辑器会很有趣,现在我正在寻找一个用 c 或 c++ 编写的简单但不错的文本编辑器,我可以从中获得灵感并学习如何自己编写文本编辑器.

Could you guys recommend a "simple but decent" text editor written in c or c++ to me ?

你们能向我推荐一个用 c 或 c++ 编写的“简单但体面的”文本编辑器吗?

采纳答案by Daff

Well what you want to see sounds more like a tutorial than an actual application (I think applications like Notepad++will be a lot to dive into in the beginning). Since you don't mention any environment you want to program in, you could check out the QT Text EditorDemo. QT is a cross platform GUI Toolkit so you are not bound to a specific operating system but probably harder to setup then a Visual Studio environment in Windows.

好吧,您想看到的内容听起来更像是教程而不是实际应用程序(我认为像Notepad++这样的应用程序一开始需要深入研究)。由于您没有提及要在其中编程的任何环境,您可以查看QT 文本编辑器演示。QT 是一个跨平台的 GUI 工具包,因此您不受特定操作系统的约束,但可能比 Windows 中的 Visual Studio 环境更难设置。

For Windows only you might want to think about digging more into the .NET platform (e.g. C#) as suggested in this question. It doesn't help learning C++ but it makes GUI development a hell of a lot easier.

仅对于 Windows,您可能需要考虑按照此问题中的建议深入研究 .NET 平台(例如 C#)。它对学习 C++ 没有帮助,但它使 GUI 开发变得容易得多。

回答by Michael Ekstrand

You might want to look at Zileor nvi. Both are fairly simple; Zile is Emacs-like, and nvi is the Berkeley vi. Another to look at would be Nano, a simple text editor that is designed to be easy for new users. I don't know how clean the code is on any of these, though.

您可能想查看Zilenvi。两者都相当简单;Zile 类似于 Emacs,而 nvi 是 Berkeley vi。另一个要考虑的是Nano,这是一个简单的文本编辑器,旨在方便新用户使用。不过,我不知道其中任何一个的代码有多干净。

I would also recommend reading The Craft of Text Editing: Emacs for the Modern World. This book surveys many of the specific problems that have to be dealt with in writing a text editor along with approaches, strategies, and algorithms for solving them. Its content should be relevant and useful even if your editor isn't going to look much like Emacs at all.

我还推荐阅读The Craft of Text Editing: E​​macs for the Modern World。本书调查了编写文本编辑器时必须处理的许多具体问题,以及解决这些问题的方法、策略和算法。即使您的编辑器看起来根本不像 Emacs,它的内容也应该是相关且有用的。

回答by luke

Notepad++is an excellent open source editor written in C++.

Notepad++是一个用 C++ 编写的优秀开源编辑器。

回答by bua

Get the vi. There is a big lack of true editors like vi/vim ;) I mean there is a plenty of editors like notepad/notepad++, but few editors which have separate command/control mode. So You could look at the vi sources to inspire yourself and introduce something revolutionary.

获取 vi。像 vi/vim 这样真正的编辑器非常缺乏;) 我的意思是有很多像记事本/记事本++这样的编辑器,但很少有编辑器具有单独的命令/控制模式。因此,您可以查看 vi 源以激发自己的灵感并介绍一些革命性的东西。

回答by Dominic Rodger

Notepad++for some definitions of "simple".

Notepad++用于“简单”的一些定义。

回答by Nick Dandoulakis

You may also check out Scintillaediting component.

您还可以查看Scintilla编辑组件。

回答by Daniel

What sort of text editor would you like to make?

你想制作什么样的文本编辑器?

First question is will this be GUI or Console based?

第一个问题是这是基于 GUI 还是基于控制台?

GUI based, do you want to make something like Notepad? And on what platform? If it's MS Windows based, might I recommend picking up on MFC?

基于图形用户界面,你想做记事本之类的东西吗?以及在什么平台上?如果它是基于 MS Windows 的,我可以推荐使用 MFC 吗?

If it's text based, there are many open source solutions you can get into. My recommendation is to look at the simplest of editors like ed or something.

如果它是基于文本的,您可以使用许多开源解决方案。我的建议是看最简单的编辑器,比如 ed 之类的。

回答by Cristian Adam

JuffEd. It is written in C++, cross platform due to usage of Qt and QScintilla. Notepad++ uses also Scintilla text editor component, but its limited only to Windows platform.

杰夫埃德。由于使用了 Qt 和 QScintilla,它是用 C++ 编写的,跨平台。Notepad++ 也使用 Scintilla 文本编辑器组件,但仅限于 Windows 平台。

回答by SomeUser

loot to the QT this is cross platform,HAVE RICHTEXT COMPONENT(widget).Writing first app in QT will give you actual knowledge.I recommend to learn QT by book

掠夺到 QT 这是跨平台的,有 RICHTEXT 组件(小部件)。在 QT 中编写第一个应用程序会给你实际知识。我建议通过书来学习 QT