55

What does the "c" mean in the cout, cin, cerr and clog names?

I would say char but I haven't found anything to confirm it.

0

3 Answers 3

85

The "c" stands for "character" because iostreams map values to and from byte (char) representations. [Bjarne Stroustrup's C++ Style and Technique FAQ]

3
  • 1
    If it is the right answer, it is not a very useful one! All iostream objects are character streams. cout, and cin are simply such objects instattiated on the stdout and stdin streams (normally the 'console'), so 'console' would seem more likley and more useful as an identifier. If they didn't already exists stdout and stdin would be obvious names for these. Of course few of the symbols in the standard library are exemplars of good naming!
    – Clifford
    Commented Feb 14, 2010 at 19:10
  • 1
    Also see page 45 of Stroustrup's Programming Principles and Practices Using C++: 'The name cout is pronounced "see-out" and is an abbreviation of "character output stream." You'll find abbreviations rather common in programming. Naturally, an abbreviation can be a bit of a nuisance the first time you see it and have to remember it, but once you start using abbreviations repeatedly, they become second nature, and they are essential for keeping program text short and manageable.'
    – eric
    Commented Mar 28, 2018 at 14:00
  • 1
    There is the wide char type in C++. There is no such concept as wide console. wcout definitely stands for "wide char out".
    – Yongwei Wu
    Commented Sep 17, 2019 at 8:23
30

I originally guessed console, and this link confirmed it. But after seeing the quote from Stroustrup, it seems that's a misconception, and that the c stands for character.

One thing in favor of that theory that can serve as an indicator is the fact that for each stream object (cin, cout, cerr, etc.) there is an equivalent, wide-stream one (wcin, wcout, wcerr, etc.).

3
  • 4
    It would be nice to have a reference from a standards document or one of Stroustrup's works for this - I can't find one, and random web pages don't count, I'm afraid.
    – anon
    Commented Feb 14, 2010 at 18:36
  • 1
    I always thought it referred to C as in C++ :) (havent thought about it much...) Commented Feb 14, 2010 at 18:38
  • @anon His Wikipedia page states that Stroustrup.com is indeed his website. Also under the accepted answer eric commented that "page 45 of Stroustrup's Programming Principles and Practices Using C++" states the same, I don't currently have access to the book but I'm going to be ordering it Commented Jan 12, 2023 at 4:37
1

FredOverflow has found the right answer with a link toward the Stroustrup web site.

A C++ standard draft (n1905.pdf on www.open-std.org; I don't have the exact link) seems to indicate that it comes from "C" : "C standard output" => cout

27.3 Standard iostream objects [lib.iostream.objects]

1- The header <iostream> declares objects that associate objects with the standard C streams provided for by the functions declared in <cstdio> (27.8.2).

[...]

27.3.1 Narrow stream objects [lib.narrow.stream.objects]

istream cin

1- The object cin controls input from a stream buffer associated with the object stdin, declared in <cstdio>.

[...]

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.