简体   繁体   English

#include iostream in C?

[英]#include iostream in C?

In C++ we always put the following at the top of the program 在C ++中,我们始终将以下内容放在程序的顶部

#include <iostream>

What about for C? C怎么样?

Well, this is called the standard I/O header. 好吧,这称为标准I / O头。 In C you have: 在C你有:

#include <stdio.h>

It's not an analog to <iostream> . 它不是<iostream>的模拟。 There is no analog to iostream in C -- it lacks objects and types. 在C中没有iostream的模拟 - 它缺少对象和类型。 If you're using C++, it's the analog to <cstdio> . 如果您使用的是C ++,则它与<cstdio>类似。

See also this fantastic question and its answer, 另见这个奇妙的问题及其答案,

#include <stdio.h> 

iostream is a C++ library for input-output. iostream是一个用于输入输出的C ++库。 The C equivalent would be stdio.h C等价物是stdio.h

#include <stdio.h>

C Standard Input and Output Library (cstdio, known as stdio.h in the C language). C标准输入和输出库(cstdio,在C语言中称为stdio.h)。 This library uses what are called streams to operate with physical devices such as keyboards, printers, terminals or with any other type of files supported by the system. 此库使用所谓的流来操作物理设备,如键盘,打印机,终端或系统支持的任何其他类型的文件。 Streams are an abstraction to interact with these in an uniform way; 流是一种以统一的方式与这些交互的抽象; All streams have similar properties independently of the individual characteristics of the physical media they are associated with. 所有流都具有相似的属性,与它们所关联的物理媒体的各个特征无关。

Streams are handled in the cstdio library as pointers to FILE objects. 流在cstdio库中作为指向FILE对象的指针处理。 A pointer to a FILE object uniquely identifies a stream, and is used as a parameter in the operations involving that stream. 指向FILE对象的指针唯一地标识流,并在涉及该流的操作中用作参数。

There also exist three standard streams: stdin, stdout and stderr, which are automatically created and opened for all programs using the library. 还有三个标准流:stdin,stdout和stderr,它们是使用库自动为所有程序创建和打开的。

In C : 在C:

#include<stdio.h> + #include<stdlib.h> to get the almost all functionality of <iostream> #include<stdio.h> + #include<stdlib.h>获取<iostream>的几乎所有功能

For example there is system() function (for windows only) in <iostream> but not in <stdio.h> . 例如, <iostream>system()函数(仅用于Windows),但<stdio.h>

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

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