Learn C++ - C++ Introduction






成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VLet's begin with a simple C++ program that displays a message.

The following code uses the C++ cout (pronounced "see-out") to produce character output.

The source code comments lines begin with //, and the compiler ignores them.

C++ is case sensitive. It discriminates between uppercase characters and lowercase characters.

Example

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VThe cpp filename extension is a common way to indicate a C++ program.


#include <iostream>                           // a PREPROCESSOR directive 
int main()                                    // function header 
{                                             // start of function body 
     using namespace std;                      // make definitions visible 
     cout << "this is a test.";  // message 
     cout << endl;                             // start a new line 
     cout << "hi!" << endl;   // more output 
     return 0;                                 // terminate main() 
}   

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VThe code above generates the following result.





Note

To make the window stay open until you strike a key by adding the following line of code before the return statement:

cin.get();

C Input and Output

If you're used to programming in C, you would not know cout but you do know the printf() function.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 V C++ can use printf(), scanf(), and all the other standard C input and output functions, if that you include the usual C stdio.h file.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VYou construct C++ programs from building blocks called functions.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VTypically, you organize a program into major tasks and then design separate functions to handle those tasks.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VThe example shown above is simple enough to consist of a single function named main().

The main() function is a good place to start because some of the features that precede main(), such as the preprocessor directive.





Note 2

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VThe sample program has the following fundamental structure:

int main() 
{ 
     statements 
     return 0; 
} 

The final statement in main(), called a return statement, terminates the function.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VThe code above has the following elements:

  • Comments, indicated by the // prefix
  • A preprocessor #include directive
  • A function header: int main()
  • A using namespace directive
  • A function body, delimited by { and }
  • Statements that uses the C++ cout facility to display a message
  • A return statement to terminate the main() function

The Function Header

The following function header states that the main() function returns an integer value to the function that calls it and that main() takes no information from the function that calls it:

int main()

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VMany existing programs use the classic C function header instead:

main()     // original C style 

Under classic C, omitting the return type is the same as saying that the function is type int.

However, C++ has phased out that usage.

You can also use this variant:

int main(void)     // very explicit style 

Using the keyword void in the parentheses is an explicit way of saying that the function takes no arguments.

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VUnder C++, leaving the parentheses empty is the same as using void in the parentheses.

Some programmers use this header and omit the return statement:

void main()