Int to cstring:
Cstring. Format ("% d", INT );
...............................
String to cstring
Cstring. Format ("% s", String. c_str ());
C_str () is indeed better than data.
.......................................
Char * To cstring
Cstring. Format ("% s", char *);
Cstring strtest;
Char * charpoint;
Charpoint = "give string a value ";
Strtest = charpoint; // pay the value directly
........................................ ...........................
Cstring to int
Cstring Ss = "1212.12 ";
Int temp = atoi (SS); // atoi _ atoi64 or atol
Converts a character to an integer. You can use atoi, _ atoi64, or atol.
Int int_chage = atoi (lpcstr) SS );
Or:
Cstring STR = "23 ";
Uint;
Sscanf (STR, "% d", uint );
..............................
String to int
..............................
Char * to int
# Include <stdlib. h>
Int atoi (const char * nptr );
Long atol (const char * nptr );
Long long Atoll (const char * nptr );
Long long atoq (const char * nptr );
........................................ ...........................
Cstring to string
String S (cstring. getbuffer ());
Releasebuffer () is required after getbuffer (). Otherwise, no space occupied by the buffer is released.
........................................ ..
Int to string
........................................ ..
Char * to string
String S (char *);
You can only initialize it. It is best to use assign () unless it is initialized ().
........................................ ...........................
Convert cstring to char *
Cstring strtest = "wwwwttttttt ";
Charpoint = strtest. getbuffer (strtest. getlength (); cstring conversion char [100]
Char A [100];
Cstring STR ("aaaaaa ");
Strncpy (A, (lpctstr) STR, sizeof (a); cstring STR = "AAA ";
Char * Ch;
Ch = (char *) (lpctstr) STR;
........................................ ..
Int to char * There is a function ITOA () in stdlib. h ()
ITOA usage:
ITOA (I, num, 10 );
I number to be converted to characters
Variable for saving characters After num Conversion
10: The base (in hexadecimal) 10 of the number to be converted. It can also be 2, 8, 16, and so on.
Prototype: char * ITOA (INT value, char * string, int Radix );
Instance:
# Include "stdlib. H"
# Include "stdio. H"
Main ()
{
Int I = 1234;
Char s [5];
ITOA (I, S, 10 );
Printf ("% s", S );
Getchar ();
}
........................................ ..
String to char *
Char * P = string. c_str ();
String AA ("AAA ");
Char * c = AA. c_str (); string mngname;
Char T [200];
Memset (T, 0,200 );
Strcpy (T, mngname. c_str ());
........................................ ...........................
There is no string in Standard C, char * = char [] = string. You can use the cstring. Format ("% s", char *) method to convert char * To cstring. To convert cstring to char *, use the operator (lpcstr) cstring. Cannot convert from 'const char * 'to 'Char *'
Const char * c = AA. c_str ();
String. c_str () can only be converted to const char *