C++ unformatted Input output operations

C++ unformatted Input output operations

Overloaded Operators >> and << We have used the objects cin and cout (pre-defined in the iostream file) for the input and output of data of various types.

The following is the general format for reading data from the keyboard:

cin >> variable >> variable 2 >> . . . . >> variable

variable1, variable 2, . . . are valid C++ language variable names that have been declared already.

This above statement will cause the computer to stop the execution and look for input data from the keyboard by help of user. The input data for this statement would be:

data1 data2 . . . . . . dataN

The input data are separated by white spaces and also should match the type of variable in the cin list. Spaces, newlines and tabs will be skipped.

in the above example operator >> reads the data character by character and assigns it to the indicated location. The reading for a variable only will be terminated at the encounter of a white space or a character that does not match the destination type.

For example, consider the following code:

int code;
cin >> code;

suppose the following data is given as input:
42580

The operator will read the characters upto 8 and the value of code variable 4258 is assigned to the code. The character D remains in the input stream and will be input to the next cin statement. The general form for displaying data on the screen is:

cout << item1 << item2 << . . . . << itemN

The items item1 through itemN may be variables or constants of any basic type. We have used such statements in a number of examples illustrated in previous chapters.

  • 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