简体   繁体   English

全局C ++ I / O对象是等效的还是使用CI / O流?

[英]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 我正在浏览有关C ++ I / O库的信息的cppreference并且到目前为止都了解它,但是有一件事情:例如,据说std :: cout

associated with the standard C output stream stdout. 与标准C输出流标准输出相关联。

what does this mean technically? 这在技术上意味着什么? Is std::cout actually using stdout or does it simply mean that std::cout is functionally equivalent to stdout? std :: cout实际上是使用stdout还是仅仅意味着std :: cout在功能上等同于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? 如果全局对象正在使用C流 - 为什么他们会使用C流而不是C ++ I / O库提供的流?

When you say "C" streams, these are really the standard streams delivered to every process by the Operating System. 当您说“C”流时,这些实际上是操作系统向每个进程传递的标准流

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. 在编写C语言之前 ,它们一直存在于操作系统中。

Obviously "C" provides access to those through <stdio.h> and C++ provides access to them through <iostream> . 显然,“C”通过<stdio.h>提供对它们的访问, C++通过<iostream>提供对它们的访问。

I think that to say the C++ library uses the "C" streams may be a little misleading. 我认为说C++库使用“C”流可能有点误导。 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). 如果我们谈论标准C库,那么C++不太可能使用它们(但需要与它们合作 )。

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). 底层标准输入/输出流不是标准C的一部分,但它们与C语言有很长的历史,因为C是专门为编写操作系统而创建的,因此Process I / O的低级核心很可能是C库(虽然它也可以是汇编程序或其他语言)。

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 . 例如,在POSIX系统上有C库头,用于访问不属于标准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. 这可能就是为什么它们在链接文档中被称为C流,但标准io流的概念早于C语言本身。

What Standard C and Standard C++ streams do is add layers of abstraction on the raw primitives provided by the Operating System. 标准C标准C ++流所做的是在操作系统提供的原始基元上添加抽象层。 This is generally formatting and converting between numbers and strings, character encodings , etc. C and C++ do those things rather differently. 这通常是在数字和字符串,字符编码等之间进行格式化和转换CC++不同的方式执行这些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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