To use memset(), what is the difference between
#include <string>       //did not work
and
#include <string.h>     //worked
Thanks!
#include <string> File extension is needed in header inclusion for C language. #include <string. h> Inclusion of <string> In C++ is recommended when the program needs to use string. The same purpose is there for inclusion of <string.
The <string> library is included in the <iostream> library, so you don't need to include <string> separately, if you already use <iostream>. "string. h" header file is for the function like strlen,strcpy,strcmp etc. without string header file you can't use these inbuilt function.
<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.
h is the header in the C standard library for the C programming language which contains macro definitions, constants and declarations of functions and types used not only for string handling but also various memory handling functions; the name is thus something of a misnomer.
<string> is a C++ standard library include, and <string.h> is C standard library include.
The equivalent of <string.h> in C++ is <cstring>, although both will work.
The difference is: <cstring> wraps everything in the std namespace whereas <string.h> puts everything in the global namespace.
Also, expect some stricter type safety rules from <cstring>.
In a modern C++ environment, you would #include <cstring> to get memset().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With