

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Standard Input Stream (cin) in C++
std::cin is an object of class istream that represents the standard input stream oriented to narrow characters (of type char). It corresponds to the C stream stdin. The standard input stream is a source of characters determined by the environment. It is generally assumed to be input from an external source, such as the keyboard or a file.
As an object of class istream, characters can be retrieved either as formatted data using the extraction operator (operator>>) or as unformatted data, using member functions such as read. The object is declared in header <iostream> with external linkage and static duration: it lasts the entire duration of the program.
You can use this object to read from standard input to a variable. For example, if you want to read an int value in a variable my_intand then print it to the screen, you'd write −
Example
#include<iostream> int main() { int my_int; std::cin >> my_int; std::cout << my_int; return 0; }
Then save this program to the hello.cpp file. Finally, navigate to the saved location of this file in the terminal/cmd and compile it using −
$ g++ hello.cpp
Run it using −
$ ./a.out
Output
If you give it the input: 15, this will give the output−
15
- Related Questions & Answers
- How to get the Standard Input and Output Stream through Console in C#?
- What is C++ Standard Output Stream (cout)?
- What is C++ Standard Error Stream (cerr)?
- Getting the Standard Output and Standard Error Output Stream through Console in C#
- How can we read from standard input in Java?
- Java Program to close this input stream and release any system resources associated with the stream
- Java Program to Read The Number From Standard Input
- How to convert an input stream to byte array in java?
- Java Program to mark the current position in this input stream
- How to convert/read an input stream into a string in java?
- Character Stream vs Byte Stream in Java
- What are cin, cout and cerr streams in C++?
- Read a character from standard input without waiting for a newline in C++
- Stream In Java
- Java Program to read the next byte of data from the input stream