The difference between three headers string / cstring /string.h of

1.

#include <cstring> // not defined string s; strcpy like functions can use
the using namespace STD;

#include <String> // define string s; strcpy not use functions such as
using namesapce std; // Note that no defined string type declaration header file is also possible

#include <string.h> // not defined string s; you can use functions such as strcpy

 

2.

1) cstring file, and the corresponding string.h, c ++ version of the header file that contains the string functions such as strcpy like
2) string.h file, and the corresponding cstring, C version of the header file, and the like comprising such strcpy string handler
3) file string, std :: comprising the defined string, STL belonging to the category
4) CString, MFC in the string class

string.h header files in C language string manipulation functions
cstring is c ++ for C language functions like strcpy stated, included after cstring, you can use C-style functions like strcpy in the program.

string is affirmed c ++ string class template language 
CString string class is defined in the MFC, MFC many classes and functions are to CString as a parameter, in addition CString class overloads (LPCSTR) operator, so if you use the following MFC CString class, you can directly call as a parameter to a function win api needs a C-style string with CString class, the compiler will automatically call (LPCSTR) member function to convert from CString to a C-style string . If you use the C ++ language standard in the MFC string class, you need to call in a C-style string for the win api parameter, you must show the call sting.c_str () member function to accomplish the same conversion, but also that is using MFC, if a CString class, it will be easy to sting a little more than class.

 

3.

. (1) First, let me cstring and string.h:
something cstring and string.h fact, there are C standard library, to achieve something in the cstring
is:  
  namespace std  
  {  
  #include <string.h>  
  }  
cstring is part of C ++, it can be said that the string.h upgraded version of C, but it is not part of C.
So if you are using C ++, then please use cstring, if you are using a C Please string.h.

(2) .string and cstring: 
generally a C ++ library old version with ".h" extension libraries, such as iostream.h, in the standard library has a new standard without the ".h" extension It corresponds to the difference in addition to the many improvements of the latter, as well as the latter point is all the stuff into the "std" namespace.      
string, std :: string file which is used in the definition of C ++, the class header file string, STL belonging to the category. There are many methods of string operations.

4.string.h is the standardization of C ++ (1998) before C ++ libraries, in the standardization process, in order to be compatible ago, standardization organizations have carried out all of these files new definition is added to the standard library, the file is added a new name on the "c" prefix and suffix .h removed, it became cstring string.h header file header. But its implementation is identical or compatible with the previous. It is equivalent to the standard library organization to cover up a chapter, he said, "You are my part of the standard library."

5.cstring represents string.h, but is encapsulated into a std inside, such as calling strlen function, you need to write std :: strlen (yourstr) for the job, using this method more in line with the requirements of the standard C ++ string is the C ++ standard library inside string template (or rather should be a specialized template), but he also included a definition of C-style string manipulation functions (should be achieved by including string.h) string.h not need to use the name space, this library is a C-style string manipulation, strlen, strcpy, strcat, strcmp ...... are there, but since it is a C-style library, of course, does not require namespace support.

 

 
 

#include <cstring> // not defined string s; strcpy like functions can use
the using namespace STD;

#include <String> // define string s; strcpy not use functions such as
using namesapce std; // Note that no defined string type declaration header file is also possible

#include <string.h> // not defined string s; you can use functions such as strcpy

 

2.

1) cstring file, and the corresponding string.h, c ++ version of the header file that contains the string functions such as strcpy like
2) string.h file, and the corresponding cstring, C version of the header file, and the like comprising such strcpy string handler
3) file string, std :: comprising the defined string, STL belonging to the category
4) CString, MFC in the string class

string.h header files in C language string manipulation functions
cstring is c ++ for C language functions like strcpy stated, included after cstring, you can use C-style functions like strcpy in the program.

string is affirmed c ++ string class template language 
CString string class is defined in the MFC, MFC many classes and functions are to CString as a parameter, in addition CString class overloads (LPCSTR) operator, so if you use the following MFC CString class, you can directly call as a parameter to a function win api needs a C-style string with CString class, the compiler will automatically call (LPCSTR) member function to convert from CString to a C-style string . If you use the C ++ language standard in the MFC string class, you need to call in a C-style string for the win api parameter, you must show the call sting.c_str () member function to accomplish the same conversion, but also that is using MFC, if a CString class, it will be easy to sting a little more than class.

 

3.

. (1) First, let me cstring and string.h:
something cstring and string.h fact, there are C standard library, to achieve something in the cstring
is:  
  namespace std  
  {  
  #include <string.h>  
  }  
cstring is part of C ++, it can be said that the string.h upgraded version of C, but it is not part of C.
So if you are using C ++, then please use cstring, if you are using a C Please string.h.

(2) .string and cstring: 
generally a C ++ library old version with ".h" extension libraries, such as iostream.h, in the standard library has a new standard without the ".h" extension It corresponds to the difference in addition to the many improvements of the latter, as well as the latter point is all the stuff into the "std" namespace.      
string, std :: string file which is used in the definition of C ++, the class header file string, STL belonging to the category. There are many methods of string operations.

4.string.h is the standardization of C ++ (1998) before C ++ libraries, in the standardization process, in order to be compatible ago, standardization organizations have carried out all of these files new definition is added to the standard library, the file is added a new name on the "c" prefix and suffix .h removed, it became cstring string.h header file header. But its implementation is identical or compatible with the previous. It is equivalent to the standard library organization to cover up a chapter, he said, "You are my part of the standard library."

5.cstring represents string.h, but is encapsulated into a std inside, such as calling strlen function, you need to write std :: strlen (yourstr) for the job, using this method more in line with the requirements of the standard C ++ string is the C ++ standard library inside string template (or rather should be a specialized template), but he also included a definition of C-style string manipulation functions (should be achieved by including string.h) string.h not need to use the name space, this library is a C-style string manipulation, strlen, strcpy, strcat, strcmp ...... are there, but since it is a C-style library, of course, does not require namespace support.

 

Guess you like

Origin www.cnblogs.com/lightworkshopnoi/p/11290027.html