Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the C++string operation corresponding to the C string function

Shulou Source: shulou.com Published: 2022-06-03 05:04:29 10月13日 Update

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

Tags: Functions characters strings content more help good appropriate location interest reason guys buddies commonly used pointers articles methods standards knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi OPPO Reno Xiaomi Huawei