C + + Primer Plus Learning Note 2.1.3 C + + preprocessor and iostream files

Source: Internet
Author: User

Program Listing 2-1 Myfirst.cpp

//Myfirst.cpp--Displays a message#include<iostream>//a preprocessor directiveintMain ()//function Header{//start of function body    using namespaceStd//Make definitions Visiblecout <<"Come up and C + + me some time.";//messagecout << Endl;//start a new linecout <<"You won ' t regret it!"<< Endl;//More output}

If your program wants to use C + + input or output tools, provide two lines of code:
#include <iostream>
using namespace Std;
You can replace line 2nd with other code, which is intended to simplify the program.
C + + and C also use a preprocessor that processes the source files before the main compilation (as described in chapter 1th, some C + + programs use a translator program to convert C + + programs to C programs. Although the translator is also a preprocessor, the preprocessor is not discussed here, but only the preprocessor, which handles the compilation instructions with the name beginning with #. You do not have to perform any special actions to invoke the preprocessor, which runs automatically when the program is compiled.
#include <iostream>//a preprocessor directive
This compilation instruction causes the preprocessor to add the contents of the iostream file to the program. This is a typical preprocessor operation: Replace or add text before the source code is compiled.
This raises a question: Why add the contents of the iostream file to the program? The answer involves communication between the program and the outside world. Io in iostream refers to input (information entered into the program) and output (information emitted from the program). The input/output scheme for C + + involves multiple definitions in the iostream file. In order to use cout to display messages, the first program needs these definitions. #include编译指令导致iostream文件的内容随源代码文件的内容一起被发送给编译器. In fact, the contents of the iostream file will supersede the code lines in the program, # include <iostream>. The original file is not modified, but the source code file and the iostream are combined into a compound file, which is used by the next stage of compilation.

Understanding: When there are #include instructions in the program, the contents of the corresponding files, such as # include <iostream>,iostream, will all be read into the current file at the beginning of the compilation.
That is, the content in the iostream file will be replaced #include <iostream>.

C + + Primer Plus Learning notes 2.1.3 C + + preprocessor and iostream files

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.