
- 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 C++ Standard Error Stream (cerr)?
std::cerr is an object of class ostream that represents the standard error stream oriented to narrow characters (of type char). It corresponds to the C stream stderr. The standard error stream is a destination of characters determined by the environment. This destination may be shared by more than one standard object (such as cout or clog).
As an object of class ostream, characters can be written to it either as formatted data using the insertion operator (operator<<) or as unformatted data, using member functions such as write. The object is declared in the header <iostream> with external linkage and static duration: it lasts the entire duration of the program.
You can use this object to write to the screen. For example, if you want to write "Hello" to the screen, you'd write −
Example
#include<iostream> int main() { std::cerr << "Hello"; 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
This will give the output −
Hello
- Related Articles
- Getting the Standard Output and Standard Error Output Stream through Console in C#
- What is C++ Standard Output Stream (cout)?
- Standard Input Stream (cin) in C++
- What is STREAM?
- C++ Program to implement standard error of mean
- What is the difference between cerr and clog streams in c++?
- What is the difference between cerr and cout streams in c++?
- What is DIX Standard?
- What is British standard system and international standard system?
- What are cin, cout and cerr streams in C++?
- How to find the standard error of mean in R?
- How to calculate standard error of the mean in Excel?
- What is RS 232C Standard?
- What is Error Detection?
- What is Error Correction?
