【问题标题】:What The Difference between stdio.h and iostream? [duplicate]stdio.h 和 iostream 有什么区别? [复制]
【发布时间】:2015-04-30 03:04:02
【问题描述】:
#include<stdio.h>
int main ()
{
    // code
}
return 0 ;
#include<iostream>
int main ()
{
    // code
}

哪个库最好用?

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

【问题讨论】:

  • stdio.h 用于 printf ...而 iostream 用于 std::cout / std::cin ...不同之处在于使用 c 函数与 c++。如果您正在编写 c++ 代码,请使用 c++。

标签: c++


【解决方案1】:

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

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

因此,如果您使用 C++,只需使用 #include &lt;iostream&gt;

【讨论】:

    【解决方案2】:

    首先,iostream 是 C++ 标准库的一部分,stdio.h 是 C 标准库的一部分。虽然 stdio.h 可以在 C++ 中工作,但它并没有提供 iostream 包含的所有内容,因为 iostream 专门用于 C++。

    这里是stdio.h documentation

    这里是iostream documentation

    【讨论】:

      【解决方案3】:

      iostream 是输入/输出类和对象的 C++ 标头(std::coutstd::cin...)。 stdio.hprintfscanf、... 的 C 标头(在 C++ 中,stdio.h 变为 cstdio

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

      【讨论】:

        猜你喜欢
        • 2011-04-20
        • 1970-01-01
        • 1970-01-01
        • 2015-11-23
        • 2013-02-13
        • 2011-04-26
        • 2016-09-24
        • 1970-01-01
        相关资源
        最近更新 更多