Linux C/C ++ Hello word

Source: Internet
Author: User

 

$ Vim Hello. c



# Include <stdio. h>


Int main (void)
{
Printf ("Hello world! /N ");
Return 0;
}



 

: The wq storage disk is Hello. c.



 

Enter gcc Hello. c-o hello in the command line (case sensitive)



 

 

 

The following warning may be reported during compilation: no newline at end of file can be supplemented with a new line at the end of the file.



 

Execution file:./hello



 





Compile C ++-"Hello world !"
# Include <iostream. h>


Int main ()
{
Cout <"Hello world! /N "<endl;
Return 0;
}
Compilation error: undefined reference to ''cout''
Ah! I don't even know how to connect to cout. Please check out what man says:
Man gcc
Oh, I used to compile the C ++ program with g ++.
G ++ Hello. cpp-o hello


 

 

Compilation class
There are three files: Hello. h, Hello. cpp, and MyFirst. cpp. The content is as follows:
File: // Hello. h

# Ifndef HelloH
# Define HelloH


Class Hello
{
Hello ();
Void Display ();
}


File: // Hello. cpp

# Include "Hello. h"
# Include <iostream. h>


Hello: Hello ()
{
}


Hello: Display ()
{
Cout <"Hello world! /N "<endl;
}


File: // MyFirst. cpp

# Include <iostream. h>
# Include "Hello. h"


Int main ()
{
Hello theHello;
TheHello-> Display ();


Return 0;
}
Start Compilation: g ++ MyFirst. cpp-o MyFirst
Ah, an error occurred:
Undefined reference to ''hello: Hello (void )''
Undefined reference to ''hello: Display ()''
Oh, it seems that the connection to Hello. cpp is not allowed. Please change it first.
In MyFirst. cpp: change # include "Hello. h" to # include "Hello. cpp"
After compilation is passed, check the help. If there is a parameter-c, only compilation is not linked.


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.