6
#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?

emlai
  • 39,703
  • 9
  • 98
  • 145
Omar Effat
  • 141
  • 1
  • 1
  • 3
  • 1
    stdio.h is for printf ... while iostream is for std::cout / std::cin ...The difference is using c functions versus c++. If you are writing c++ code use c++. – drescherjm Feb 27 '15 at 11:52

3 Answers3

32

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

iostream is the input output class in C++

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

Bas
  • 4,123
  • 8
  • 33
  • 52
14

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++.

Here is stdio.h documentation.

Here is iostream documentation.

emlai
  • 39,703
  • 9
  • 98
  • 145
Nick Suwyn
  • 461
  • 1
  • 5
  • 21
5

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)

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

vincentp
  • 1,365
  • 8
  • 12