C++ stdio.h 和 iostream 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28764438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 21:03:15  来源:igfitidea点击:

What The Difference between stdio.h and iostream?

c++

提问by Omar Effat

#include<stdio.h>
int main ()
{
    // code
}
return 0 ;
#include<iostream>
int main ()
{
    // code
}

Which library is best to use?

哪个库最适合使用?

What is the best and why? And when I code what is the difference in function between them?

什么是最好的,为什么?当我编码时,它们之间的功能有什么区别?

回答by Bas

stdio.his the header file in the C standard library. It is used for input/output

stdio.h是 C 标准库中的头文件。它用于输入/输出

iostreamis the input output class in C++

iostream是C++中的输入输出类

So if you're using C++ just use #include <iostream>

因此,如果您使用的是 C++,请使用 #include <iostream>

回答by Nick Suwyn

First off, iostreamis part of the C++ standard library, and stdio.his part of the C standard library. While stdio.hwill work in C++ it does not provide everything that iostreamincludes as iostreamis specifically for C++.

首先,iostream是 C++ 标准库的stdio.h一部分,也是 C 标准库的一部分。虽然stdio.h用C将工作++它不提供的一切,iostream包括为iostream是专门为C ++。

Here is stdio.hdocumentation.

这是stdio.h文档

Here is iostreamdocumentation.

这是iostream文档

回答by vincentp

iostreamis the C++ header for the input / output classes and objects (std::cout, std::cin...). stdio.his the C header for printf, scanf, ... (in C++, stdio.hbecame cstdio)

iostream是输入/输出类和对象 ( std::cout, std::cin...)的 C++ 头文件。 stdio.hprintf, scanf, ...的 C 头文件(在 C++ 中,stdio.h变成了cstdio

In C++, you are not supposed to use it, use iostreaminstead.

在 C++ 中,你不应该使用它,iostream而是使用它。