Standard Error Stream Object - cerr in C++ Last Updated : 26 Aug, 2025 Comments Improve Suggest changes Like Article Like Report The standard error stream in C++ is a special output stream used to display error messages or warnings. It is represented by std::cerr and sends messages to the screen, just like std:: cout . However, unlike std:: cout, it is unbuffered, meaning it shows messages immediately. This helps in debugging by showing errors right away, even if the program crashes.Example: CPP #include <iostream> using namespace std; int main() { // Printing message immediately to the console- unbuffered cerr << "Welcome to GfG! :: cerr\n"; // Printing after the program execution completes- buffered cout << "Welcome to GfG! :: cout"; return 0; } ErrorWelcome to GfG! :: cerrWelcome to GfG! :: coutBuffered vs Unbuffered OutputA buffer is like a temporary storage area ( a "waiting room") for data before it is shown or written.Feature Buffered OutputUnbuffered OutputWhat it doesStores output in memory temporarilySends output directly (immediately)When it shows upShows later (when buffer is full or flushed)Shows immediatelyUsed bystd::cout, std::clogstd::cerrUse caseFor regular output (not urgent)For errors or important messagesWhat is Redirection?Redirection means sending output (like messages or errors) to a different place instead of the screen.Normally, when we run a C++ program.std:: cout (normal output) andstd:: cerr (error output) both print to the screen ( called the console or terminal).But with redirection, we can tell our program:"Send the output somewhere else, like a file."Redirection of std::cerr (Error Messages) C++ #include <iostream> #include <fstream> using namespace std; int main() { // This will go to the console cout << "This is normal output (cout).\n"; // This will be redirected to a file cerr << "This is an error message (cerr).\n"; return 0; } In the file error_log.txt:This is an error message written to a file.How to Compile and Run with Redirectiong++ main.cpp -o myprogram # Compile the program./myprogram 2> error_log.txt # Run the program and redirect std::cerr to a fileOutput on Screen:This is normal output (cout).Why Redirect std::cerr?Saves Errors: So we can check them later, especially if our program crashes.Log files: Useful for programs that run often (like servers or scripts).Keep things separate: Separate normal results from error messages for clarity.Debugging: Helps track down what went wrong and when. Comment More infoAdvertise with us T trohila10 Follow Improve Article Tags : C++ CPP-Library cpp-input-output Practice Tags : CPP Explore C++ Programming Language 5 min read C++ OverviewIntroduction to C++ Programming Language 3 min read Features of C++ 5 min read History of C++ 7 min read Interesting Facts about C++ 2 min read Setting up C++ Development Environment 8 min read Difference between C and C++ 3 min read C++ BasicsUnderstanding First C++ Program 4 min read C++ Basic Syntax 4 min read C++ Comments 3 min read Tokens in C 4 min read C++ Keywords 2 min read Difference between Keyword and Identifier in C 3 min read C++ Variables and ConstantsC++ Variables 4 min read Constants in C 4 min read Scope of Variables in C++ 7 min read Storage Classes in C++ with Examples 6 min read Static Keyword in C++ 5 min read C++ Data Types and LiteralsC++ Data Types 7 min read Literals in C 4 min read Derived Data Types in C++ 4 min read User Defined Data Types in C++ 4 min read Data Type Ranges and Their Macros in C++ 3 min read C++ Type Modifiers 4 min read Type Conversion in C++ 4 min read Casting Operators in C++ 5 min read C++ OperatorsOperators in C++ 9 min read C++ Arithmetic Operators 4 min read Unary Operators in C 5 min read Bitwise Operators in C 6 min read Assignment Operators in C 4 min read C++ sizeof Operator 3 min read Scope Resolution Operator in C++ 4 min read C++ Input/OutputBasic Input / Output in C++ 5 min read cin in C++ 4 min read cout in C++ 2 min read Standard Error Stream Object - cerr in C++ 2 min read Manipulators in C++ 4 min read C++ Control StatementsDecision Making in C (if , if..else, Nested if, if-else-if ) 7 min read C++ if Statement 3 min read C++ if else Statement 3 min read C++ if else if Ladder 3 min read Switch Statement in C++ 5 min read Jump statements in C++ 4 min read C++ Loops 7 min read for Loop in C++ 6 min read Range-Based for Loop in C++ 3 min read C++ While Loop 3 min read C++ do while Loop 4 min read C++ FunctionsFunctions in C++ 8 min read return Statement in C++ 4 min read Parameter Passing Techniques in C 3 min read Difference Between Call by Value and Call by Reference in C 4 min read Default Arguments in C++ 5 min read Inline Functions in C++ 6 min read Lambda Expression in C++ 4 min read C++ Pointers and ReferencesPointers and References in C++ 5 min read C++ Pointers 8 min read Dangling, Void , Null and Wild Pointers in C 6 min read Applications of Pointers in C 4 min read Understanding nullptr in C++ 3 min read References in C++ 5 min read Can References Refer to Invalid Location in C++? 2 min read Pointers vs References in C++ 5 min read Passing By Pointer vs Passing By Reference in C++ 5 min read When do we pass arguments by pointer? 5 min read Like