Of all the programs in CPP, the most important is always two points: input and output.
Next, we'll familiarize ourselves with the input and output of the CPP using an example.
For example, enter two numbers, output their and:
#include <iostream>//use Cin,cout to call iostream library or compile error
using namespace Std;
the int main ()//main program function, which is owned in all CPP programs, is the starting point for the CPP program to run
{
int A, B; Define shaping variables A, b
cin>>a>>b; Input A and B
cout<<a+b; Output of A+b and
return 0; The return statement of main function main (), which represents the end of the program
}
Description:
1: #include <iostream>
using namespace Std;
int main ()
{
return 0;
These statements are the framework of all CPP programs, and beginners must keep in mind that recite!!!
2: About CPP Program input: In CPP language input is generally used cin.
3: about the output of the CPP program: Enter the general use cout in the CPP language.
4: About CIN: Use ">>" connection between number and number (characters and characters) when using CIN for input (two greater than sign)
4: About cout: When using cout to output, in the number and number (character and character) between the need for "<<" connection (two less than the number), if the output is a single character, enclosed in one or double quotation marks, such as cout<< ' K '; cout<< "K"; 。 If the output is multi-character, you must enclose it in double quotation marks, as
cout<< "yes"; 。 If the output is an expression, do not add any symbols. PS: The space is "" or "; Change behavior <<endl;.
5:cpp arithmetic operators: + (plus),-(minus), * (multiply),/(except),% (for redundancy)
Example: 1+4=5
60-32=28
4*18=72
9/3=3 14/4=3 (The division operation of CPP will automatically remove decimals and become divisible)
17%4=1 (this is for redundancy)
Let's take a look at two more examples:
#include <iostream>
using namespace Std;
int main ()
{
int a,b,c;
cin>>a>>b>>c;
cout<<a*b%c;
return 0;
}
#include <iostream>
using namespace Std;
int main ()
{
cout<< ' A ' << ' << ' happy! ' <<endl;;
return 0;
}
Homework:
1: Try to define six variables, use all CPP five operators, and output. Be familiar with the arithmetic operators of CPP.
2: Output three single character (no matter, no short lattice)
3: Output three multi-character (no matter, short lattice)
Zerojudge:
General title: a001,a002,d827,d049,d126,d483
Study questions: d053,d461,d296,a042,a044
Rokua:
General title: p1001
Study questions: p1421
Basic input and output