Difference between string.h and cstring?

前端 未结 7 1266
耶瑟儿~
耶瑟儿~ 2020-12-03 03:13

What is the difference between string.h and cstring?

Which one should be used for C and which one for C++ (if at all)?

7条回答
  •  有刺的猬
    2020-12-03 04:06

    There is a subtle difference between string.h and cstring

    Answer of Alf P. Steinbach (can be found as a comment to the asked question):

    string.h places the identifiers in the global namespace, and may also place them in the standard namespace. While cstring places the identifiers in the standard namespace, and may also place them in the global namespace. You definitely don't want that cstring behavior, because code that e.g. uses just strlen may work fine with one compiler, then fail to compile with another compiler. It's very unpleasant surprise. So for C and C++, use the more safe string.h.

提交回复
热议问题