clog

Learn via video courses
Topics Covered

Overview

The clog is an object of ostream class of C++. It is used for error and event logging purposes. The object is declared in the iostream header. It is associated with the stderr, standard error output stream.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of clog in C++

The clog object is used along with the insertion operator << to output the characters to the standard error stream, which is a default destination for error messages and other diagnostic warnings.

Parameters of Clog in C++

clog is not a function, so it doesn't have the concept of parameters. It is used along with the insertion operator to print characters.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Return Value of Clog in C++

clog is not a function, so it also doesn't have the concept of the return value.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example

In this example, we are printing the log(kind of information) with the help of a clog object.

Output:

How does Clog in C++ Work?

clog means character log. This object is associated with the standard error output stream in C++, so we can output the characters to show the warnings and errors.

The cerr object, associated with the stderr, is also used to print the errors to the standard error output stream. Still, the stream in clog is buffered, which means the characters will be first fed into an allocated space named buffer, and then the characters will be written to standard stream at once. The clog stream, which works with a buffered stream, is much more efficient than cerr because there is no need to write the data continuously. Still, at the same time, it is risky. If the system crashes in between the runtime, then if there is some error or diagnostic message stored in the buffer, that message will be lost.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

More Example

Invalid File Open

In this example, we will see how we can use clog for logging purposes, we are going to open a file, and for details about the operation inside the code, we will provide concurrent logs.

Output 1: If file fails to open,

Output 2: If file opens successfully,

Conclusion

  • clog is an object of the ostream class.
  • The clog object is declared in the iostream header.
  • To make this object work in the program,
    • Either we can use a std namespace like this using namespace std;.
    • Or scope resolution operator with std keyword like this std::.
  • It prints the error messages and warnings to the standard error output stream, stderr.
  • Unlike the cerr and similar to cout, it is associated with a buffer.
  • It provides more efficiency than cerr but less reliability because the error messages might not be visible immediately and hence can be lost due to buffering process.