CSTRING and INT, FLOAT types are converted.

xiaoxiao2021-04-03  199

1. Int <-> cstring

1) Int -> cstring

INT n = 1;

CString Str;

Str.Format ("% d", n);

2) cstring-> int

CSTRING STR = "1";

INT N = ATOI (Str.getBuffer (0));

2. CHAR * and CSTRING

1) Char * -> CString

Char SZ [128];

CString Str;

Str.Format ("% s", sz);

2) CSTRING -> char *

CString Str;

INT NLENGTH = Str.getLength ();

Char * sz = new char [NLENGTH];

SZ = str.getBuffer (0);

3. Float <-> cstring

1) float-> cstring

Float f = 0.0;

CString Str;

Str.Format ("% f", f);

2) cstring-> float

CString Str = "0.0";

Float f = atof (str.getBuffer (0));

转载请注明原文地址:https://www.9cbs.com/read-131500.html

New Post(0)