Basic Input / Output in C++ Last Updated : 09 Oct, 2025 Comments Improve Suggest changes 722 Likes Like Report Try it on GfG Practice In C++, data is read and written using streams, which are sequences of bytes.Input stream: Data flows from a device (like the keyboard) to the computer’s memory.Output stream: Data flows from memory to an output device (like the screen).These streams are defined in the <iostream> header file.The most common stream objects are - cin : for taking input, cout : for displaying output. Standard Output Stream - coutcout is an instance of the ostream class used to display output on the screen.Data is sent to cout using the insertion operator <<. C++ #include <iostream> using namespace std; int main() { // Printing the given text using cout cout << "GeeksforGeeks"; return 0; } OutputGeeksforGeeksStandard Input Stream - cincin is an instance of the istream class used to read input from the keyboard.The extraction operator >> is used with cin to get data from the input stream and store it in a variable. C++ #include <iostream> using namespace std; int main() { int age; // Taking input from user and store it in variable cin >> age; // Output the entered age cout << "Age entered: " << age; return 0; } Output18 (Enter by user) Your age is: 18Un-buffered Standard Error Stream - cerrcerr is the standard error stream used to display error messages. It is an instance of the ostream class.cerr displays messages immediately, without waiting (Unbuffered output)Useful for showing errors or warnings separately from normal program output (cout).Unlike cout, which may delay output due to buffering, cerr ensures errors are seen instantly.Note: The main difference between cerr and cout comes when you would like to redirect output using "cout" that gets redirected to file if you use "cerr" the error doesn't get stored in file.(This is what un-buffered means ..It cant store the message) C++ #include <iostream> using namespace std; int main() { cerr << "An error occurred"; return 0; } ErrorAn error occurredBuffered Standard Error Stream - clogclog is the standard logging stream used to display error or log messages. It is an instance of the ostream class, like cerr.Messages are first stored in a buffer and displayed only when the buffer is full or explicitly flushed using flush() (Buffered output)Useful for logging messages that don’t need to appear immediately on the screen.Unlike cerr, output from clog may be delayed due to buffering. C++ #include <iostream> using namespace std; int main() { clog << "An error occurred"; return 0; } ErrorAn error occurredRead related article Difference between cerr and clog Create Quiz Input Output Introduction in C++ Visit Course Comment H Harsh Agarwal 722 Improve H Harsh Agarwal 722 Improve Article Tags : Misc C++ cpp-input-output CPP-Basics school-programming CBSE - Class 11 +2 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like