Difference between and ?

前端 未结 10 994
囚心锁ツ
囚心锁ツ 2020-11-27 15:52

How come this code

std::map  m;
m[\"a\"]=1;

compiles with (I\'m using MSVC 2010)

#include 

        
相关标签:
10条回答
  • 2020-11-27 16:19

    I believe <string.h> is just used for C and <string> for C++. So including string.h wont work.

    0 讨论(0)
  • 2020-11-27 16:21
    • <string.h> contains old functions like strcpy, strlen for C style null-terminated strings.
    • <string> primarily contains the std::string, std::wstring and other classes.
    0 讨论(0)
  • 2020-11-27 16:22

    <string.h> is cstring - http://www.cplusplus.com/reference/clibrary/cstring/

    <string> is the c++ string class - http://www.cplusplus.com/reference/string/

    Edit per Nicol Bolas comment below and a bit of googling:

    <cstring> will usually import the same things as <string.h> but into the std namespace. <string.h> will usually import everything into the global namespace. It appears to depend on the library implementation you're using though according to my googling.

    Personally I only ever use <cstring> if I need C style string helpers.

    0 讨论(0)
  • 2020-11-27 16:29

    <string.h> contains C-library string functions. strlen, strcmp, etc.

    <string> contains the definition for std::basic_string, which has the typedefs std::string and std::wstring. That's the difference.

    They really have no relationship at all, outside of the fact that they both deal with strings.

    0 讨论(0)
提交回复
热议问题