[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 $