cpp input operator

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

#include<iostream> // include header file
using namespace std;
int main()
{
int age;
cout << "Enter your age:";
cin >> age;
cout << "\nYour age " << age;
return 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.

#include<iostream>
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

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise