I am new to C++ and tutorials use both <iostream>
and <stdio.h>
. Which one would be best to use?
Asked
Active
Viewed 225 times
0

Remy Lebeau
- 555,201
- 31
- 458
- 770

Ella
- 11
-
3Be careful with C++ tutorials. Don't confuse C and C++. Look for tutorials made after 2011 as the language changed a lot year. Tutorials that use `#include
` tends to indicate that the tutorial is meant for C instead of C++ since standard C++ header includes don't end in `.h`. – François Andrieux Jan 28 '22 at 17:42 -
1First of all, if you use `
`, I would recommend using the c++ standard library ` – 2pichar Jan 28 '22 at 17:42`, which would work with inputs of c++ classes. -
1Unrelated: @Ella I would recommend learning C++ using [good C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) instead of videos. – Jason Jan 28 '22 at 17:44
-
The C++ I/O allows for overloading `operator>>` and `operator<<` for customized structs and classes. The C I/O system is restricted to the primary types. My recommendation is to stay with the C++ I/O system (and stay away from online judges). – Thomas Matthews Jan 28 '22 at 17:51
-
2Note: If your tools are up-to-date you may find `
` easier to use than both. – user4581301 Jan 28 '22 at 18:10
1 Answers
2
This leans heavily into opinion, but <stdio.h>
is a C header, so generally the answer would be <iostream>
. If you feel the need to use the C header in a C++ program, include it this way:
#include <cstdio>

Remy Lebeau
- 555,201
- 31
- 458
- 770

Chris
- 26,361
- 5
- 21
- 42