54

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.

NAND
  • 663
  • 8
  • 22
Rexxar
  • 1,886
  • 1
  • 14
  • 19

3 Answers3

84

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

Community
  • 1
  • 1
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
  • 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 Feb 14 '10 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 "**c**haracter **out**put 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 Mar 28 '18 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 Sep 17 '19 at 08:23
29

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.).

NAND
  • 663
  • 8
  • 22
JRL
  • 76,767
  • 18
  • 98
  • 146
  • 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. –  Feb 14 '10 at 18:36
  • 1
    I always thought it referred to C as in C++ :) (havent thought about it much...) – Viktor Sehr Feb 14 '10 at 18:38
  • @anon [His Wikipedia page states that Stroustrup.com is indeed his website](https://en.wikipedia.org/wiki/Bjarne_Stroustrup). Also under the accepted answer [eric](https://stackoverflow.com/users/1886357/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 – jgh fun-run Jan 12 '23 at 04: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>.

[...]

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rexxar
  • 1,886
  • 1
  • 14
  • 19