Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <string> and <string.h>?

How come this code

std::map <std::string , int> m; m["a"]=1; 

compiles with (I'm using MSVC 2010)

#include <string> 

but not with

#include <string.h> 

?

like image 926
Valmond Avatar asked Feb 13 '12 08:02

Valmond


People also ask

What is difference between string and string h?

<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.

Is string H and CString same?

Apparently cstring is for C++ and string. h is for C. One thing worth mentioning is, if you are switching from string. h to cstring , remember to add std:: before all your string function calls.

What is meant by string H?

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. Functions declared in string.

Why do we use #include string h?

h is the header file required for string functions. This function appends not more than n characters from the string pointed to by src to the end of the string pointed to by dest plus a terminating Null-character.


1 Answers

  • <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.
like image 148
Ajay Avatar answered Oct 09 '22 07:10

Ajay