C++ Input operator
The statement
cin>>value;
in the above example the input statement and causes the program to wait for the user(input) to type in a number. The number keyed in is placed in the variable value. and The identifier cin(input operator) is a predefined object in c++ that corresponds to the standard input stream. Here this stream represents the keyboard
cou << string;
you can be call that the operator << is bitwise left-shift operator and it can still be used for this purpose. this is an example of how one operator can be used for different works.
so we can also say this concept is know as opearator overloading.
in the c language we use printf() function for displaying string on screen.
This operator >> is known as The extraction (get from operator). It extracts(or takes) the value from the keyboard and (allocate)assigns it to the variable on its right. this is same as scanf() in c programming. like the << bitwise operator it can be oberloaded.
take the example
cout << “answer =” << value << “\n”;
so first sends the string “answer=” to cout(output operator) and then sends the value of value variable. finally it sends the newline character so that the next output will be in the new line. The multiple use of<
cout <<“sum is” << sum << “\n” << “multiplication is”<< mul << “\n”
in the above example this one statement print two lines
sum is=12
multiplication is 34
example
cin >> value1 >> value2
the values are assigned from left to right that is if we key in two values these are 10 and 20 then 10 will be assigned to value1 and 20 to value2
using namespace std;
main()
{
age;
cout << "Enter your age:";
cin >> age;
cout << "\nYour age " << age;
0;
}
|
Standard input stream (cin)
The cin operator is a predefined object of class istream. It takes input from standard input device,
which is a usually keyboard. The cin operator is used in conjunction with stream extraction (>>) operator to get or read the input from a console.
Standard end line (endl)
The endl is also predefined object of ostream class. It is used to insert a new line characters and
flushes the stream.
using namespace std;
int main( ) {
cout << "C++ Tutorial programmingknow.com";
cout << " C and c++" << endl;
cout << "End of line" << endl;
}
|
C++ Tutorial programmingknow.com C and c++
End of line
|