Is it bad practice to use a C header instead of its C++ equivalent in C++ (e.g. stdio.h instead of cstdio)?

前端 未结 4 1138
北海茫月
北海茫月 2021-01-14 04:22

It seems that a lot of people include example.h instead of cexample in their C++ code. I know that everything in the C++ versions is declared in namespace std, but I\'m not

4条回答
  •  借酒劲吻你
    2021-01-14 04:53

    The difference between the two is that the C headers that C++ imported (by prefixing with c and removing the .h suffix) are in namespace std. This so any call or use of a standard facility is prefixed with std::, for uniformity. It's The Standard Way Of Doing Things(tm). Unless of course you already have a bunch of C code in which you don't feel like appending std:: to each standard call: then use the classic C headers.

提交回复
热议问题