[C + + can learn this] the beginning of two studies

Source: Internet
Author: User

The beginning of the second study

1. Preparatory work

工欲善其事 its prerequisite, learning programming is no exception, before learning we need to prepare an IDE (Integrated development environment). Don't rush to ask questions, let me slowly tell you, so-called programming you can simply rough understand to put a bunch of code ( Codes) writes to a text and then transforms it into an executable file through a compilation process. Typically, the compilation process requires source code → preprocessor (preprocessor) → compiler (compiler) → Assembler (assembler) → object code → linker (Linker) → executable (executables) process, you will be sure to make an exclamation: too complicated! That's how I learn! So the IDE appears, The IDE integrates this complex process, and when you've written the code, simply press a key, and the IDE automatically executes the process and eventually gets the executable file.

There are many IDE environments in C + +, such as the famous Visual Studio series, Code::blocks,visual C++,qtcreator and so on, I recommend using bloodshed dev-c++, you can go to HTTP.// Bloodshed-dev-c.en.softonic.com/download get it for free.

Here I would like to explain, when you have a certain understanding of programming, be sure to get rid of the IDE to try to compile manually, which may make you encounter difficulties, but the harvest is absolutely satisfactory to you.

2.hello World

Now let's start writing the famous Hello World program and use it as your first C + + program.

First open dev-c++, select File->source file (source)

Then enter the following code

2.2 Hello_world-to print Hello World #include <iostream> int main () {    std::cout<< ' Hello World ';    return 0;}

After you have entered this code, continue to press File->save as (Save As) and select the name Helloworld.cpp last saved.


The effect of this code is to output a "Hello World" character on the computer screen, and now let's analyze it in one line.

First See first line

In C + +//and/**/means comments, just like the comments on some classical words in your Chinese book, its purpose is to make your code more concise and understandable, they will not be written into the program, that is, no matter how many comments you write will not affect the efficiency of your program. Maybe you'll raise the question. And since it's a comment, why should we both be present//and/**/? I'm glad you raised such a question, which shows that you are already reading this article carefully. C + + can not open such a silly joke,//and/**/is the difference between//means that the comment line of text, when the second line of its loss of function;/**/can annotate you across multiple lines, like this.

Hello world/*helloworld*/

And see the second line.
#include <iostream>

This is the preprocessor directive for C + +, which is very clear, both on the surface and in substance, that it contains a file, specifically a header file. The so-called inclusion of the file is written by others to include the program code in your program, just as someone wrote a program to create 1 of the Earth, you feel dissatisfied with the idea of changing it to create 5 of the Earth's program, then you can include someone else to write the program, and then loop to execute five times, although this example is not OK, But what we're talking about now is the essence of inclusion rather than actually doing it, you need to be prepared. I have already said that it contains the header file, where is the file? No doubt iostream is the header file, the header file is a standard C + + file, is the code provided by others, you can easily include and use it.

Followed by

int main () {}
Notice here that I put two curly braces together, the surface of which they must exist in pairs. When you see here has indicated that you saw the C + + gate, it is a pity that I can not tell you what it means, I hope you learn gradually. Now I can simply tell you that its name is function, and you might be surprised that this doesn't seem to have anything to do with the math function. Again sorry these questions can only tell you later, what you need to know now is that the main code of C + + is composed of functions and classes (Class). Now keep in mind that your doubts continue to look down.

std::cout<< "Hello World";

This is the core of the program, because it shows the Hello world, unfortunately she is even more complicated than the above function, because this is a class, so I'm not going to tell you all about him now, what you need to know now is that the quotation marks contain the content is the character, You can modify it to let the program output other content, such as your name.

return 0;
The last sentence means that the program quits normally, and I will slowly say something about its substance.


Your first program will be completed here, but I don't think you will be too happy, because there are too many questions like sticks that blow your confidence in learning. Here I want to first feel that it blows you, if you can accept such a blow I would be very happy, such a heavy blow can withstand the back of your study will not have any obstacles. Finally, adjust your mood and read on.


[C + + can learn this] the beginning of two studies

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.