C++ Of Hello World

C Linguistics is in a hurry , And they started to make contact C++, Which leads to the following content can not be well grasped . Now decide to put something down , Review from the beginning C++.
The compiler I chose is C-free5.0, Because it took a long time , I don't want to change it .
By convention , Every programmer learns a new language , The first program to always write is Hello World!
Here is the code :

#include
using namespace std;
int main()
{
cout<<“Hello World”<<endl;
return 0;
}

This involves C++ And C The first difference in language , Even though C++ yes C Superset of , Most C Language in C++ Can be supported by China . But because it's a review C++, So I didn't use the header file <stdio.h>, It's a choice iosteam Library files ,iostream Means iostream library .iostream I / O stream , Directly speaking in( input )
out( output ) stream( flow ), take in,out And stream synthesis .
#include It doesn't need to be like C Same language , add .h, This is in C++ It is also reflected in other libraries .
The next step is using namespace
std; This sentence is actually using Compile instructions , Why compile instructions are used , Because C++ Designed considering the compatibility of the program on different products , When our preprocessed library function does not .h Time , To use using instructions , If any , This command is not required .
The above is equivalent to the following code :

#include
//using namespace std;
int main()
{
std::cout<<“Hello World”<<std::endl;
return 0;
}

We can see , Not used using Compiling instructions can also be completed , But it needs to be added before each instruction std::, It's not worth it . In addition, I put using The command is on main Outside function , So the scope is global , You can also put it in main In function .

#include
int main()
{
using namespace std;
cout<<“Hello World”<<endl;
return 0;
}

But in that case , Only for main In function , If you use a subfunction , You need to use it again at the beginning of each subfunction using instructions .

cout It's a C++ New concept in , stay C In language , We passed printf Equal function to output , and C++ The concept of flow is introduced ( Actually scanf Function runtime , This concept is also reflected in the dark ).
cout<< Add the element you want to output , Can be output by intelligence , No need to look like C Linguistic printf Function declared that way .
endl yes C++ A new introduced element of , Equivalent to newline . Here are some equivalent codes :

printf(“Hello World\n”);
cout<<“Hello World\n”;
cout<<“Hello World”<<endl;
cout<<“Hello”<<" "<<“World”<<endl;

Technology
©2019-2020 Toolsou All rights reserved,
Bitcoin in ten years ,VDS Opportunity or fraud Don't annoy the panda with any cat !「 Kung Fu Panda 」20 It's the year of man 4 blood sort ( one ) bubble sort Random forest R Language implementation java Realize the function of grabbing red packets Python Basic knowledge and notes python To solve the problem of dictionary writing list in CSS architecture design Vue Common features ( one )2021 year 2 Monthly programmer salary statistics , average 15144 element