Convert MFC cstring to int, double, and Char Types
// Convert cstring to int <br/> cstring szport = l "2589"; <br/> int nport = _ ttoi (szport ); </P> <p> // convert cstring to double <br/> cstring szport = l "2589.00"; <br/> double nport = _ ttol (szport ); </P> <p> // convert other types to cstring <br/> int nport = 2589; <br/> char IP [32] = "this way "; <br/> cstring STR; Str. empty (); <br/> Str. format (_ T ("% d: % s"), nport, ip ); </P> <p> // convert cstring to tchar * <br/> cstring CSTR (L "hello"); <br/> tchar * pstr = CSTR. getbuffer (STR );
Char and wchar_t
/* -------------------------------------- <Br/> file: Mr. h <br/> using macros to define the same function name can avoid modifying the compiler compiling environment <br/> --------------------------------------- */<br/> # pragma once </P> <p> # ifndef mr_h <br/> # define mr_h </P> <p> # ifdef Unicode <br/> # DEFINE _ mrstrncpy wcsncpy <br/> # DEFINE _ mrstrcpy wcscpy <br/> # define _ mrstrlen wcslen <br/> # DEFINE _ mrstrcat wcscat <br/> # DEFINE _ mrstrcmp wcscmp <br/> # else <br/> # DEFINE _ mrstrncpy strncpy <br/> # DEFINE _ mrstrcpy strcpy <br/> # DEFINE _ mrstrlen strlen <br/> # DEFINE _ mrstrcat strcat <br/> # DEFINE _ mrstrcmp strcmp <br/> # endif </P> <p> # endif