Conversion between CString and INT, CHAR *, CHAR [100]

xiaoxiao2021-03-06  78

CSTRING Transmission INT

Convert characters to an integer, you can use ATOI, _ATOI64 or ATOL.

To convert the numbers to a cString variable, you can use the cstring Format function. Such as

CString S;

INT i = 64;

S.Format ("% d", i)

The Format function is very strong, it is worth studying.

Void cstrdlg :: onbutton1 ()

{

// Todo: Add Your Control Notification Handler Code Here

Cstring

SS = "1212.12";

INT TEMP = ATOI (SS);

Cstring aa;

Aa.Format ("% D", TEMP);

AfxMessageBox ("VAR IS" AA);

}

Sart.Format ("% s", buf);

CSTRING CHAR *

/// char * to cstring

CString strtst;

Char * charpoint;

Charpoint = "Give String a value";

strTest = charpoint;

/// cstring to char *

Charpoint = strTest.getBuffer (STRTEST.GETLENGTH ());

There is no string in the standard C, char * == char [] == String

You can use CString.Format ("% s", char *) to convert char * to cstring. To convert CString into char *, you can use operator (lpcstr) cstring.

CString Conversion Char [100]

Char a [100];

CString Str ("AAAAAA");

STRNCPY (a, (lpctstr) STR, SIZEOF (A));

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

New Post(0)