C ++ Quick Start

Source: Internet
Author: User


[Html]
# Include <iostream>
Int main ()
{
Std: cout <"Enter two numbers:" <std: endl;
Int v1, v2;
Std: cin> v1> v2;
Std: cout <"The sum of" <v1 <"and" <v2 <"is" <v1 + v2 <std: endl;
Return 0;
}

Output:
[Html]
Pateo @ pateo-B86N53X :~ /Work/study $ g ++-o main. cc
Pateo @ pateo-B86N53X :~ /Work/study $ ls
Main. cc
Pateo @ pateo-B86N53X :~ /Work/study $./main
Enter two numbers:
1
2
The sum of 1 and 2 is 3
Pateo @ pateo-B86N53X :~ /Work/study $

[Html]
Pateo @ pateo-B86N53X :~ /Work/study $./main
Enter two numbers:
4 6
The sum of 4 and 6 is 10
Pateo @ pateo-B86N53X :~ /Work/study $


Endl Description: Operator. When writing it to the output stream, it has the effect of output line feed, and refreshes the buffer associated with the device. By refreshing the buffer, the user can immediately see the output written to the stream.

Other Instructions: c ++ also has the front ++ and back ++, and the corresponding basic syntax such as for loop is the same

[Html]
# Include <iostream>
Int main ()
{
Int sum = 0, value;
While (std: cin> value)
Sum + = value;
Std: cout <"Sum is" <sum <std: endl;
Return 0;
}

Stop action: ctr + d twice
Output:
[Html] www.2cto.com
Pateo @ pateo-B86N53X :~ /Work/study $./main
1 2 3 Sum is 6
Pateo @ pateo-B86N53X :~ /Work/study $

 

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.