#include <string.h>
const char *C_STR ();
Returns a string address, which is a C function that returns the type const char*
The C_STR () function returns a pointer constant to the normal C string, with the same contents as this string string.
This is to be compatible with the C language, there is no string type in C, so the string object must be converted to a string style in C by using the member function C_str () of the String class object.
Note: Be sure to use the strcpy () function and so on to manipulate the pointer returned by the method C_str ()
It's not right.
char* C;
String s= "1234";
c = S.c_str ();
This should be used:
Char c[string s="1234"
C_STR () returns a string containing string in char* form
If a function requires the char* parameter, you can use the C_str () method:
string s = "Hello world!";
printf ("%s", S.c_str ()); Output "Hello world!"
The. C_STR () is used where char* is needed. If you just need to deal with strings, you don't need this at all.
However, all C-language functions and some IO-related functions of C + + (such as the constructor called when creating a file stream object) require a string with a char*-type parameter and do not support string types, which can be used to get a char* pointer with the. C_STR () of a String object. .
C_str () function