1.2 input and output
note:
C++ language does not define any statements to do IO. Instead, C++ include an extensive standard library that provides IO.
Fundamental to the iostream library are two types named istream and ostream, which represent input and output streams.
The object of type istream named cin.
The object of type ostream named cout, cerr, clog.
The << operator takes two operands : the left-hand operand must be an ostream object, the right hand operand is a value to print. The operator writes the given value on the given ostream. The result of the output operator is its left-hand operand.
std::cout<< "hello"; //string literal
std::cout<<std::endl; //manipulator
endl has the effect of ending the current line and flushing the buffer associated with that devise.
std::cin>>v1>>v2;
The input operation reads two values from std::cin, storing the first in v1 and the second in v2.
Using names from standard library: the prefix std:: indicates that the names like cout is defined inside the namespace named std.
Avoid inadvertent collisions between the name we defined and the name inside a library.
All the names defined by the standard library are in the std namespace.
exercise:
exercise 1,3
<span style="font-size:14px;">#include<iostream>
int main()
{
std::cout<<"Hello, World"<<std::endl;
system("pause");
return 0;
}</span>
exercise 1.4
<span style="font-size:14px;">#include<iostream>
int main()
{
int a=0,b=0;
std::cin>>a>>b;
std::cout<<a*b<<std::endl;
system("pause");
return 0;
}</span>
exercise 1.5
<span style="font-size:14px;">std::cout<<"The sum of ";
std::cout<<v1;
std::cout<<" and ";
std::cout<<v2;
std::cout<<" is ";
std::cout<<v1+v2;
std::cout<<std::endl;</span>
exercise 1.6
This program is illegal because there is no ostream object in the second and the third statement.
You can add std::cout to the second and the third statement.
Or you can just remove ";" from the first and the second line.