这段代码是怎么回事
std::map <std::string , int> m;
m["a"]=1;使用编译(我使用的是MSVC 2010)
#include <string>但不是用
#include <string.h>发布于 2012-02-13 16:53:34
<string.h>包含了像strcpy,strlen这样的老函数,用于C风格的以null结尾的字符串。<string>主要包含std::string、std::wstring和其他类。发布于 2012-02-13 16:50:37
string.h是C标头而不是C++标头,句号!
发布于 2012-02-13 16:51:51
字符串是cstring - http://www.cplusplus.com/reference/clibrary/cstring/
<string>是c++字符串类- http://www.cplusplus.com/reference/string/
根据Nicol Bolas下面的评论进行编辑,并在谷歌上搜索一下:
<cstring>通常会将与<string.h>相同的内容导入到std名称空间中。<string.h>通常会将所有内容导入到全局命名空间中。不过,根据我的谷歌搜索,这似乎取决于您正在使用的库实现。
就我个人而言,我只在需要C风格的字符串帮助器时才使用<cstring>。
https://stackoverflow.com/questions/9257665
复制相似问题