May 5, 2024

Telugu Tech Tuts

TimeComputers.in

C++ tutorial in telugu using cin Part 3

c++ tutorial in telugu

Standard input (cin)

In this tutorial we will take a look at basic input and output. Using the C++ iostream library we will get the user’s input from the keyboard and we will print messages onto the screen. The iostream library is part of the C++ standard library.

In C++, I/O is performed by using streams. A stream is a “stream of data” in which character sequences are “flow into” or “flow out off.” A stream is an object with properties that are defined by a class. Global objects are predefined for the standard I/O channels.

The header file iostream must be included to make use of the input/output (cin/cout) operators.

In most cases the standard input device is the keyboard. With the cin and >> operators it is possible to read input from the keyboard.

Take a look at an example:


	#include<iostream>
	using namespace std;

	int main()
	{
		char MY_CHAR;
		cout << "Press a character and press return: ";
		cin >> MY_CHAR;
		cout << MY_CHAR;
		return 0;
	}

Note: The input is processed by cin after the return key is pressed.

The cin operator will always return the variable type that you use with cin. So if you request an integer you will get an integer and so on. This can cause an error when the user of the program does not return the type that you are expecting. (Example: you ask for an integer and you get a string of characters.) Later on we will offer a solution to this problem.

The cin operator is also chainable. For example:


       cin >> XX >> YY;

In this case the user must give two input values, that are separated by any valid blank separator (tab, space or new-line).

That’s all for this tutorial.