Cstring转char、string、int等数据类型的方法(国外英文资料).docVIP

  • 8
  • 0
  • 约7.7千字
  • 约 13页
  • 2017-06-05 发布于河南
  • 举报

Cstring转char、string、int等数据类型的方法(国外英文资料).doc

Cstring转char、string、int等数据类型的方法(国外英文资料)

Cstring转char、string、int等数据类型的方法 Unicode the CString is converted to char * Method one: use the API: WideCharToMultiByte for conversion CString STR = _T ( D: \ the school project \ \ qq.bmp ); / / note: the following n and len values are different, n is calculated by character, and len is calculated by bytes Int n = STR. GetLength (); / / n = 14, len = 18 / / to get the size of the wide byte character, the size is calculated by bytes Int len = WideCharToMultiByte (CP_ACP, 0, STR, STR. GetLength (), NULL, 0, NULL); / / for the multi-byte character array application space, the size of the array is the size of the byte bytes in bytes Char * pFileName = new char [len + 1]; / / in bytes / / wide byte encoding translates into multi-byte encoding WideCharToMultiByte (CP_ACP, 0, STR, STR. GetLength (), pFileName, len, NULL); PFileName [len + 1] = \ 0; / / multi-byte characters end with \ 0 Method 2: use functions: T2A, W2A CString STR = _T ( D: \ the school project \ \ qq.bmp ); / / declare identifier USES_CONVERSION; / / call functions, T2A and W2A both support character conversion in both ATL and MFC Char * pFileName = T2A (STR); / / char * pFileName = W2A (STR); / / the transformation can also be implemented Note: you may also need to add reference # include afxpriv.h Unicode below char * converts to CString Method one: use the API: MultiByteToWideChar for conversion A char * pFileName = D: \ the school project \ \ QQ. / / compute the char * array size, in bytes, and a Chinese character in two bytes Int charLen = strlen (pFileName); / / calculate the size of multi-byte characters by character. Int len = MultiByteToWideChar (CP_ACP, 0, pFileName, charLen, NULL, 0); / / for a wide byte character array application space, the array size is the size of multi-byte characters calculated in bytes TCHAR buf = new TCHAR [len + 1]; / / multi-byte encoding translates into wide byte encoding MultiByteToWideChar (CP_ACP, 0, pFileName, charLen, buf, len); Buf [len] = \ 0; / / to add t

文档评论(0)

1亿VIP精品文档

相关文档