Compile the hello World C language program in Linux

Source: Internet
Author: User
I used it like this. Program
# Include <iostream. h>
Int main (void)
{
Int I, J;
J = 0;
I = J + 1;
Cout <"Hello world! "<Endl;
Cout <"The result is" <I <Endl;
Return 0;
}
Use G ++-O test. cpp. However, there is an error in this case, prompting that iostream. h cannot be opened and modified to such a program.
# Include <iostream>
Using namespace STD;
Int main (void)
{
Int I, J;
J = 0;
I = J + 1;
Cout <"Hello world! "<Endl;
Cout <"The result is" <I <Endl;
Return 0;
}
The running result of G ++-O test. cpp is correct.
<Iostream> and <iostream. h> It is different. The former has no suffix. In fact, you can see in your compiler include folder that the two are two files. When you open the file, you will find that Code Is different.
Suffix. h header file C ++ standards have been explicitly proposed not to support, earlier implementation of the standard library function defined in the global space, declared in the. in the header file with the suffix H, the C ++ standard is used to distinguish it from C, and to correctly use the namespace, it is required that the header file does not use the suffix. h.
Therefore, when <iostream. h> when <iostream> is used, it is equivalent to calling the library function in C and using a global namespace, that is, the early C ++ implementation, the header file does not define a global namespace. You must use namespace STD; To use cout correctly.
Secondly, when programming in Linux, the C ++ program can save in the format of. CC. C. cpp ......

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.