C ++ char *, char [], String, cstring Conversion
*********************************
Char * --------> char []
-------------------------------------------
Char * ADDR;
Char [20] address;
Strcpy (address, ADDR );
*********************************
String ----------> cstring
-----------------------------------------
String;
Cstring str1;
Str1 = A. c_str ();
********************************
Cstring ----------> char []
------------------------------------
Cstring str1;
Char szchar [20];
Strcpy (szchar, (char *) (const char *) str1 );
***********************************
String -----------> Number
Strcpy (temp, "123 ");
If it is: Short INTEGER (INT)
I = atoi (temp );
If it is a long integer (long)
L = atol (temp );
If it is: Floating Point (double)
D = atof (temp );
If it is a cstring variable
Cstring name = temp;
******************************
Number -----------> string
1) Short INTEGER (INT)
ITOA (I, temp, 10); // convert I to a string and put it into temp. the last digit indicates decimal.
ITOA (I, temp, 2); // convert in binary mode
2) long integer (long)
Ltoa (L, temp, 10 );
3) floating point number (float, double)
Fcvt can be used to complete the conversion. This is an example in msdn:
Int decimal, sign;
Char * buffer;
Double Source = 3.1415926535;
Buffer = _ fcvt (source, 7, & decimal, & sign );
Running result: Source: 3.1415926535 Buffer: '20180101' decimal: 1 sign: 0
Decimal indicates the decimal point position, sign indicates the symbol: 0 is a positive number, and 1 is a negative number.
Cstring variable
STR = "2008 Beijing Olympics ";
Buf = (lpstr) (lpctstr) STR;