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

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Omar Effat
  • 191
  • 1
  • 1
  • 4
  • 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

37

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,423
  • 8
  • 36
  • 53
17

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.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Nick Suwyn
  • 501
  • 1
  • 5
  • 21
8

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,433
  • 9
  • 12