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
What The Difference between stdio.h and iostream?
提问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.h
is the header file in the C standard library. It is used for input/output
stdio.h
是 C 标准库中的头文件。它用于输入/输出
iostream
is 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, iostream
is part of the C++ standard library, and stdio.h
is part of the C standard library. While stdio.h
will work in C++ it does not provide everything that iostream
includes as iostream
is specifically for C++.
首先,iostream
是 C++ 标准库的stdio.h
一部分,也是 C 标准库的一部分。虽然stdio.h
用C将工作++它不提供的一切,iostream
包括为iostream
是专门为C ++。
Here is stdio.h
documentation.
这是stdio.h
文档。
Here is iostream
documentation.
这是iostream
文档。
回答by vincentp
iostream
is the C++ header for the input / output classes and objects (std::cout
, std::cin
...).
stdio.h
is the C header for printf
, scanf
, ... (in C++, stdio.h
became cstdio
)
iostream
是输入/输出类和对象 ( std::cout
, std::cin
...)的 C++ 头文件。
stdio.h
是printf
, scanf
, ...的 C 头文件(在 C++ 中,stdio.h
变成了cstdio
)
In C++, you are not supposed to use it, use iostream
instead.
在 C++ 中,你不应该使用它,iostream
而是使用它。