Hello World! in C++
Translated from Chinese by Claude. Read the original
I’m starting a series on the C++ programming language. The goal is to explain C++ and teach everyone how to use it. My steps will follow roughly the same order as the book C++ Primer, so you could say I’m retelling C++ Primer in my own words!
First off, C++ Primer is an absolutely amazing book. It explains things in really, really fine detail, though I haven’t finished it myself. Let’s take it one step at a time. I’ll use the plainest language I can to walk you through the algorithms, the syntax and so on…… OK, on to lesson one. I won’t waste words on what C++ is. Lots of CPP textbooks spend page after page on how CPP was born, which is a total waste of resources. From what I’ve seen, plenty of people can’t remember anything from later in the book, yet they can recite the history of CPP at the front by heart. That history stuff can be skipped in a sentence or two. C++ Primer, for example, doesn’t spend pages on the birth of C++. I’ve noticed that the worse the C++ textbook, the more filler it has…… OK, that’s the end of my own filler…… First, I should mention that I’m using Microsoft Visual Studio 2010 as my compiler. It’s easy to find; just download one online.
![]()
Then open it. On the Start Page there’s an option to create a new project. Click it.
![]()
![]()
① In the templates on the left, choose Visual C++ under Installed Templates. My Visual C++ option is already expanded; that depends on the default development environment you picked. Then in the middle ② choose Win32 Console Application ③ Next, fill in the project’s name in the box at the bottom (you could call it the solution name). I typed cpp-1-02 ④ Finally, click OK
![]()
A Win32 Application Wizard dialog will appear. Click Next
![]()
No need to change anything; keep the default options. If you hover over each option you’ll get an explanation, like this
![]()
Finally, click Finish, and the project is created
![]()
OK, that’s how to create the most basic C++ project. Now let’s start writing the simplest “Hello World!” program! About C++: every C++ program contains one or more functions, and one of them must be named main. In the VS editor this function is _tmain, which comes from the compiler: depending on whether the program uses Unicode characters, the function may be named main or wmain. Both wmain and _tmain are Microsoft-specific. For C++, the ISO/ANSI-standard name for the main function is main. In all my ISO/ANSI C++ examples I’ll use the name main.
Here’s the source code. It’s very simple, and I’ve added comments
About comments: C++ has two kinds, single-line comments and paired comments. A single-line comment starts with a double slash (//), and the paired comment markers (/* */) are inherited from C. I won’t go into detail on those. OK, let’s look at the source code
1 |
|
Click Yes
![]()
OK, see whether “Hello World!” shows up~ That’s it for today’s tutorial~ Look forward to the next one, which introduces C++ control structures and gives a brief intro to classes.
PS: This post was a difficult birth. A long time passed after my last promise before I finally finished it. Posts like this are actually really hard to write, since you have to think about how the reader will take it……