1

I noticed that some C++ textbooks use C functions like printf as std::printf (include via <cstdio> rather than <stdio.h>).

However, in most C++ codes I saw in Github (including those written by professional developers), they just use <stdio.h> and printf. No sane programmer will name his function as printf or any famous C-function names anyway as other readers will likely to get confused.

It looks like there is no real benefit of using std::printf other than having to type more characters.

John London
  • 1,250
  • 2
  • 14
  • 32

1 Answers1

0

Namespacing in C++ allows for you to define functions that would clash with C functions. Including cstdio instead of stdio.h and using std::printf allows you for having a function called, say rename without having it clash with stdio's rename. That's what namespaces are for, actually.

Luís Guilherme
  • 2,620
  • 6
  • 26
  • 41