C + + study notes: Hello World

Source: Internet
Author: User

the first C + + program "Hello World"

As a student of C + +, I am honored to share My learning experience with all of you.

Where do we start? Start with the famous "Hello World". The code is as follows:

 //uses the VI editor under Linux for source code input, compile, and link using the GCC compiler. VC6 and VS can refer to their own compiler manuals. 
1 #include <iostream>2 using namespace Std; 3 Main ()//note should be int main () 4 { 5 cout<< hello World Span style= "color: #800000;" > " <<ENDL; 6 return 0 7 }

After writing the above code with the VI editor, compile, link, and execute it with the GCC compiler, you can see "Hello World" appearing on the screen. The first C + + program was born!
Now look back to write the source code, to probably see a C + + program composition.

First line of the first sign "#", what is this thing? This symbol is a preprocessing symbol in C + +, what is preprocessing? preprocessing refers to the processing of C + + source code by the preprocessor before the C + + program source code is compiled. The meaning of "include" is obvious, which means "import". Within a pair of angle brackets is the name of the file to import (iostream). The first line means: Import a file named iostream. The imported files are often called "header files" by C + + programmers, as iostream itself will be explained later, as long as it is clear that you want to output to the screen must have "iostream" this header file.

The second line uses a using statement, namespace means "namespace", Std is the name of that space! The namespace is described in more detail later. The second line means: Use the namespace Std.

int main () {/**/} is the main function of C + +, and a C + + program has only one main function as the entry point for C + + programs. int is the return value of the main function.

Cout is an object of the C++i/o Stream class library, meaning "output (to screen)". "<<" is a shift operator, which is described in the operator. "Hello World" is a "string", so-called "string" is "a string of characters." The function of the Endl is to wrap and refresh the stream. The specific meanings of cout, <<, Endl, and "flow" are described in the I/O library.

return 0; This statement: The main function returns the value of the return of the 0,main function as follows: Return 0 indicates that the C + + program is working properly, and if it returns non-0, it does not work properly. This return value is returned to the system.

#include < header files >

the int main ()//main function may have parameters

{

/* Function Body */

}

is the basic structure of C + + programs, and later our program basically follow this structure.

Note: 1. #include <iostream.h> is the C language style of writing, C + + is not recommended.

The standard return value of the 2.main function is int,void main () and is not recommended.

C + + study notes: Hello World

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.