What is the C++string operation corresponding to the C string function
This article introduces you what is the corresponding C++string operation of C string function, the content is very detailed, interested friends can refer to, hope to be helpful to you.
String is a standard class in STL. It is used to using pointers to manipulate char * strings in C, but it is not very suitable at first. The main reason is that no suitable C++ replacement method has been found for functions in string.h. Therefore, the function substitution in commonly used sring.h is explained as follows:
Strcpy: str.substr ()
Strncpy: str.substr (pos, n)
Strcmp: = =
Strncmp: = =
Strstr: str.find ()
Strcat: str.append ()
Strchr: str.find ()
Strtok: no corresponding function, use str.find () to wrap a str.split ()
The ultimate trick:
Conversion between char * and string
Convert char to string: string str (char)
Convert string to char *: str.c_string ()
Extended Learning:
String (substr () function)
# include#includeusing namespace std;int main () {string str; cin > > str; cout