简体   繁体   中英

Are the global C++ I/O objects equivalent or using the C I/O streams?

I am browsing cppreference for information about the C++ I/O library and understand it all so far, but there is one thing though: For instance, it is said that std::cout is

associated with the standard C output stream stdout.

what does this mean technically? Is std::cout actually using stdout or does it simply mean that std::cout is functionally equivalent to stdout?

In case that the global objects are using the C streams - why would they use C streams instead of the streams provided by the C++ I/O library?

When you say "C" streams, these are really the standard streams delivered to every process by the Operating System.

When a process is created the Operating System creates several low level "file descriptors" that enable input and output to it.

How these underlying standard input/output streams are implemented and in what language is down to the operating system. They have existed in operating systems since before the C language was written.

Obviously "C" provides access to those through <stdio.h> and C++ provides access to them through <iostream> .

I think that to say the C++ library uses the "C" streams may be a little misleading. If we are talking about the Standard C Library then it is unlikely that C++ will utilize those (but it is required to cooperate with them).

The underlying standard input/output streams are not part of Standard C , but they do have a long history with the C language because C was created specifically for writing Operating Systems and so the low level core of Process I/O is likely to be a C library (although it could also be assembler or another language entirely).

For example on POSIX systems there are C library headers for accessing the low level standard input/output streams that are not part of Standard C . This maybe why they are referred to as C streams in your linked documentation however the concept of standard io streams predates the C language itself.

What Standard C and Standard C++ streams do is add layers of abstraction on the raw primitives provided by the Operating System. This is generally formatting and converting between numbers and strings, character encodings , etc. C and C++ do those things rather differently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM