C++ Notes 003: Start with a small program

 


 Original notes, please indicate the source for reprinting!

Click [Follow], attention is also a virtue~


 

After installing VS2010, start with the first applet.

When learning C language, I first output a greeting to the world that programmers are very familiar with: hello world! I still output such a greeting!

Enter the content in the Hello.cpp file:

#include "iostream" //include C++ header files

using namespace std;//Use namespace

void main()

{

    printf("hello world!");

    system("pause");

}

The header file on the first line has learned C language, and I can still understand it to some extent. The std namespace on the second line is unintelligible. std is the standard namespace (a lot of standard definitions are defined in this namespace, such as Input and output streams, etc.), don't worry too much about this first, and will be explained in detail later.

Debug the program and find that the running result is exactly the same as that of the C language! It seems that the output function printf used in C language can also be used in C++!

Now I comment out the line of printf, because C++ is C++ after all, which is different from C language. It has some things of its own. Now modify the code.

#include "iostream"//Include C++ header files

using namespace std;//Use namespace

void main()

{

    //printf("hello world!\n");

    cout<<"hello world !"<<endl;

    system("pause");

}

cout is an object, which is equivalent to standard output, which is to output content in a "black window", for the time being.

<<This left shift operator, we found that it has "smelled". The function has been transformed in C++, which is different from the previous left shift operator in C language. This is the operator overloading in C++, which will be discussed later. !

endl means newline!

Therefore, the cout statement means printing to the screen, and carriage return and line feed.

Run the program again and find that the output is the same as before!

 

 


 Original notes, please indicate the source for reprinting!

More exciting, please pay attention to the WeChat public account: programming according to law


 

 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325010034&siteId=291194637