C++ use of string class member function c_str of

  • 2020-04-02 01:44:20
  • OfStack

1. Prototype of string class member function c_str() :

Const char * c_str () const; // returns a null terminated c string

2. C_str () function returns a pointer to a normal c string. The contents are the same as the object of the string class itself.

3. When manipulating the return value of c_str() function, you can only use c string manipulation functions, such as strcpy().

Eg:
Char * name [20].

String PTR = "tongnono";

Strcpy (name, PTR. C_str ()); //c_str() returns a temporary pointer variable that cannot be manipulated.


Related articles: