What does the "c" mean in cout, cin, cerr and clog?
Asked Answered
S

3

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.

Shareeshareholder answered 14/2, 2010 at 18:29 Comment(0)
I
84

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

Icky answered 14/2, 2010 at 18:42 Comment(3)
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!Kandacekandahar
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.'Gymno
There is the wide char type in C++. There is no such concept as wide console. wcout definitely stands for "wide char out".Rem
S
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.).

Scapula answered 14/2, 2010 at 18:30 Comment(3)
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.Kooky
I always thought it referred to C as in C++ :) (havent thought about it much...)Surbased
@Kooky 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 itEruption
S
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>.

[...]

Shareeshareholder answered 14/2, 2010 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.