The author is Xie Enming, an official account of Programmer Union (wechat id: CoderHub). Please indicate the source of reprint. Original: www.jianshu.com/p/bcdfbf661…


The whole series of C++ quest

Content abstract


  1. preface
  2. Essential tools for programming
  3. Choose your IDE
  4. conclusion
  5. Part 1 Lesson 3 Notice

1. Introduction


After the first part of c + + to explore a class trip | lesson 1: what is a c + +, after everyone is flexing its muscles, a good game?

In this lesson, we will do some preparation work before C++ development.

2. Necessary tools for programming


In your opinion, what software is necessary for programming?

If you’ve taken that lesson seriously, you can name at least one.

The compiler, by the way. This important program converts your source code (written with instructions in a high-level language like C) into binary code that your computer can understand (only zeros and ones, like 01100110001111011101010).

As we mentioned in the last lesson, there is a compiler for each high-level language (of course, for an interpreted language like Python, compilation is not required. However, Python is also compiled to bytecode and then interpreted by the virtual machine.) there are many compilers for C++ alone. Commonly used is G++ (GNU C++ Compiler). GNU is the internationally renowned free software Foundation. GNU is a recursive abbreviation for “GNU is Not Unix”.

Foreigners are always naughty and like to pick names with some programming knowledge, such as Linux Is a recursion of “Linux Is Not Unix”. Or use a lot of animal names or ICONS, especially fun).

What other tools do we need besides a compiler?

Without further ado, here are the basic tools for programming:

  • Text Editor: Test Editor. A tool for writing source code. In theory, Windows Notepad can also be used as a text editor. However, it’s best to use a text editor that is more advanced, such as one that allows you to highlight code and jump from code to code. Personally highly recommended text editors are Vim, Emacs, VS Code, Atom, Sublime, etc.

  • Compiler: Compiler. Already mentioned, to convert (or compile) your source code into binary code.

  • Debugger: Debugger. A tool used to track and find errors in a program. There’s a new word here: debug. A: I have a problem with bugs. B: I have a problem with bugs. I have a problem with bugs. Bugs are commonly referred to as bugs, supposedly because of legendary female programmer Grace Hopper (Grace Hopper). Hope) once the MARK II computer (that’s relatively large early computer) found a moth, the moths led to this computer crashes (between computer relay), hope moths caught out with a pair of tweezers, with transparent tape on a notebook, and indicate “first found worms (bug) instance”. Since then, the term debug has been used to mean the action of eliminating a program error. Hope’s notebook, along with the “lovely” moth, is now on display at the Museum of American History.

Of course, if you’re “adventurous” and like challenges, you don’t have to use the debugger (there are a few tricks you can use to figure out what went wrong). However, I think in general you will need a debugger.

So, we have two options:

  1. Use a separate text editor, compiler, and debugger. It’s more complicated, but it works. Especially in the Linux environment, many programmers still like to use this way to program, maybe not install, just want this feel, which is very cool.

  2. Use a piece of software that combines all three tools. This software is called an IDE (Integrated Development Environment).

It may be hard to decide at first, which one to use? Even if you choose to use an IDE, you will struggle with which IDE to use.

One thing is for sure: no matter what tool you choose, you can write the program you want. It’s just efficiency, personal habits, and platform-specific requirements.

Personal opinion: if you are new to C++, try to learn C++ programming from the Linux command line. Don’t rely too much on the IDE at first. Because the IDE is so good, it has prompts, auto-complete code, auto-add code for you, you don’t learn much, you don’t remember much. Wait until you get better at programming, then use an IDE, which can make your programming more efficient. It is a good choice to start writing C++ with a text editor, compiling C++ with G++, and debugging C++ with GDB (GNU Debugger).

Of course, we’ll cover a few common ides at length.

3. Choose your IDE


We thought we’d show you a few of the most famous ides, all of which are free:

  • Code::Blocks: Not bad IDE. Free, open source, cross-platform. It runs on macOS, Windows, Linux and most other operating systems.

  • Visual Studio: The base version is chargeable. There is a version of Visual Studio Express (now called Visual Studio Community) that is free. VS is fully functional and the debugger is powerful. It runs only on Windows operating systems.

  • Xcode: As Apple’s flagship IDE, Xcode really does a great job. It can be used to develop basic widgets, write iPhone and iPad apps (emulators are super fast), smartwatch apps, and write games in conjunction with other engines like Unity 3D. It only runs on Apple’s macOS operating system.

  • Eclipse: Eclipse is a well-known open source free IDE. Eclipse was originally designed as an IDE for Java development. Eclipse IDE for C/C++ Developers Can be in www.eclipse.org/downloads/p… Download the.

  • Clion: Cross-platform IDE. By far the best IDE in C or C++ in my opinion is developed by JetBrains. JetBrains’ IDE stars also include PyCharm (Python), WebStorm (JavaScript), IntelliJ IDEA (Java and Kotlin), GoLand (for Go), etc. JetBrains also makes the Kotlin language and publishes Android Studio, the strongest developer IDE for Android, in partnership with Google. JetBrains’ Clion IDE is a very powerful IDE with a very good user experience. Cons: The base version is charged. However, if you are a student or teacher, or the purpose is to classroom teaching, or do you have a good open source project, etc., can enjoy free JetBrains or breaks, please see www.jetbrains.com/idea/buy/#d… .

Code::Blocks


Code::Blocks is a very good IDE, but it is only available in English, of course there is a Chinese version online.

But since learning programming, as far as possible to pass the English, also do not need too strong English, the foundation is good. After all, some translation of the Chinese version is not in place, which may affect the use. And good programming resources are basically in English.

Please refer to my article why English is More important than Math for programmers. How to Learn.

Download Code: : Blocks

Go to the Code: : Blocks of the official download page: www.codeblocks.org/downloads/b… .

  • For Windows users, download the file at the end of.exe. Be careful to download the one with the mingw in the name (codeblocks 20.03mingw-setup.exe, for example), because a version without mingw that does not include a compiler can be troublesome.

  • For Linux users, download the version for your operating system.

  • Apple macOS users please download the macOS version (it seems that the macOS version is lagging behind).

Install run Code::Blocks

Code::Blocks setup is too easy, just like installing QQ, default all the way to the end.

After installation, double click to run, you can see the interface as shown below:

Four areas are indicated in the figure above:

  1. Toolbars: There are lots of buttons, but only a few are the ones we really use all the time.

  2. Project file list area: The left column shows all the files for your project

  3. Main interface: where code is written

  4. Notification bar: You’ll see runtime errors, compilation problems, and more

How do you create a basic console application in C++?

First go to the menu, File -> New -> Project, will open the following window:

As you can see, Code::Blocks supports a wide variety of application types using different libraries, such as SDL (developing 2D applications), OpenGL (developing 3D applications), Qt and wxWidgets, to name a few.

For now, most of these ICONS are just nice to look at, because you haven’t installed the corresponding library yet, so they can’t be used. For the time being, we’ll just use the basic Console Application.

Select Console Application and click the Go button to Go to the next step:

In the Project Title, fill in the name of the Project you want to create. We filled in the famous HelloWorld. Folder to create project in is the path to select the project.

Click Next to go to Next:

We don’t have to change anything here, the default is fine. Click Finish to complete the configuration, and Code::Blocks will create your first project.

Visual Studio


Download the Visual Studio, recommend to visualstudio.microsoft.com/downloads official download page. Choose the version suitable for your operating system to download.

You can refer to the installation and use of online graphic tutorials.

This should look like Code::Blocks:

Xcode


There are plenty of ides in the macOS operating system, but Xcode is the favorite of many Apple users.

Not all Apple users are programmers, so Apple doesn’t pre-install Xcode with macOS. You need to download Xcode from the Mac App Store (you need to have an Apple account, you can’t sign up for one).

It’s easy to Install. Just go to the App Store, search for Xcode, and click Install to Install it into your App. Get Xcode up and running:

Then select Create a new Xcode Project and the following window will pop up:

Select OS X -> Application -> Command Line Tool and click Next to go to Next:

In Project Name, fill in the Project Name, and we fill in HelloWorld. Select C++, click Next, and you’ll be asked to select the path for your project folder. Then click Finish.

Once the project is open, click the triangle button and run, and you’ll see Hello World! :

Powerful Visual Studio Code


By the way, for C++ development now, you can also use Visual Studio Code (VS Code for short), Microsoft’s open source Code editor.

VS Code itself is a Code editor, but its rich plug-ins make it a decent IDE. VS Code is cross-platform (it runs on Windows, Linux, and macOS), small and fast, and has become a favorite of many developers.

If you don’t want to install a larger IDE like Visual Studio, you can also try VS Code.

VS Code’s official website is code.visualStudio.com. After downloading, it is very easy to install, just like installing ordinary software.

When you open VS Code, for a programming language such as C++, you simply install the corresponding official plug-in (developed by Microsoft) to run and debug the language and become an IDE for that language.

For example, I installed Microsoft’s official C++ plug-in in VS Code.

Microsoft’s embrace of open source since Satya Nadella became CEO has done a lot for the Internet over the years.

4. To summarize


  1. There are generally three tools needed to get a program from the start to run: a text editor, a compiler, and a debugger. (For interpreted languages like Python, compilation is not required. Of course, Python is similar to Java in that it is compiled to bytecode and then interpreted and executed by the Python virtual machine.

  2. We can use these three tools separately to accomplish tasks. But it’s easier to develop using an IDE (integrated development environment, a mix of all three).

  3. CLion, Eclipse, Code::Blocks, Visual Studio, Xcode are well-known IDES. Of course, there are many excellent ides, which I will not cover in detail. Ides are just tools. You can also write C++ programs using text editors such as Vim, Emacs, Sublime, VS Code, and Atom. VS Code can become a lightweight C++ IDE by installing C++ plug-ins.

  4. While taking this course, you can choose your development environment as you like, not necessarily like me.

5. Part 1 lesson 3 Notice


That’s all for today’s lesson, come on!

The next lesson: the first part of c + + to explore trip | lesson 3: your first c + + program


My name is Xie Enming, the operator of the public account “Programmer Union” (wechat id: CoderHub), the moOCs elite lecturer Oscar, and a lifelong learner. Love life, like swimming, a little cooking. Life motto: “Run straight for the pole”