
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What is the difference between cin and cout streams in c++?
cin is an object of the input stream and is used to take input from input streams like files, console, etc. cout is an object of the output stream that is used to show output. Basically, cin is an input statement while cout is an output statement.
They also use different operators. cin uses the insertion operator( >> ) while cout uses the extraction operator( << ).
For example, if you want to read an int value in a variable my_int(using cin) and then print it to the screen(using cout), 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 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 Articles
- What are cin, cout and cerr streams in C++?
- What is the difference between cerr and cout streams in c++?
- What is the difference between printf() and cout in C++?
- What is the difference between cerr and clog streams in c++?
- What is the difference between System.out, System.in and System.err streams in Java?
- Difference between Streams and Collections in Java 8
- Streams and Byte Streams in C#
- What is C++ Standard Output Stream (cout)?
- What is the necessity of byte streams and character streams in Java?
- What is the difference Between C and C++?
- What is the difference between | and || operators in c#?
- What is the difference between JavaScript and C++?
- What is the difference between ++i and i++ in c?
- What is the difference between literal and constant in C++?
- What is the difference between ++i and i++ in C++?

Advertisements