本文介绍了iostream是否包含cstdio的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Dev C ++ 5.11。 TDM-GCC 4.8.1

I use Dev C++ 5.11. TDM-GCC 4.8.1

并且此代码运行良好。

#include<iostream>
using namespace std;

int main()
{
printf("%d\n", 42);
cout << "good";
}

但是据我所知,iostream不包含 printf。 ()

But as far as I know, iostream does not include "printf". (http://en.cppreference.com/w/cpp/header/iostream)

为什么运行此代码? iostream acutally包括printf吗?

Why this code run? iostream acutally include printf? Is it a kind of standard?

推荐答案

系统/标准头文件中包含的头文件列表取决于库实现(通常与您使用的编译器相关联),并且(据我所知)C ++标准并不禁止一个头文件自动包含另一个头文件

The list of header files included in a system/standard header file is library implementation dependent (that is usually associated with the compiler you're using), and (as far as I remember) the C++ standard does not prohibit one header file from automatically including another one

在您的情况下,< iostream> 也可能包含#include < stdio.h> (或< cstdio> )。

In your case <iostream> is probably also #including <stdio.h> (or <cstdio>).

依赖包含在另一个文件中的头文件不可移植到不同的标准库,编译器和平台,因此最好确保您明确地#include所需的所有内容。

Relying on a header file being included in another is non portable to different standard libraries, compilers and platforms, so it's better to make sure that you explicitly #include everything you need.

这篇关于iostream是否包含cstdio的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 05:46