C++ 包括 string 或 string.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7673597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
include string or string.h
提问by lukmac
To use memset(), what is the difference between
使用memset(),有什么区别
#include <string> //did not work
and
和
#include <string.h> //worked
Thanks!
谢谢!
回答by RushPL
<string>is a C++ standard library include, and <string.h>is C standard library include.
<string>是C++标准库包含,<string.h>是C标准库包含。
The equivalent of <string.h>in C++ is <cstring>, although both will work.
<string.h>在 C++ 中的等价物是<cstring>,尽管两者都可以工作。
The difference is: <cstring>wraps everything in the stdnamespace whereas <string.h>puts everything in the global namespace.
区别在于:<cstring>将所有内容都包装在std命名空间中,而<string.h>将所有内容都放在全局命名空间中。
Also, expect some stricter type safety rules from <cstring>.
此外,期待一些更严格的类型安全规则来自<cstring>.
回答by Ernest Friedman-Hill
In a modern C++ environment, you would #include <cstring>to get memset().
在现代 C++ 环境中,您将#include <cstring>获得memset().

