MFC中使用UNICODE情况下怎么把UINT型转换为CString

Techay 2015-09-05 09:10:26
在MFC中把UINT转换为CString,总是有误差,在unicode情况下使用itoa也不行,求问
...全文
449 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-09-06
  • 打赏
  • 举报
回复
_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow Convert an integer to a string. char *_itoa( int value, char *string, int radix ); char *_i64toa( __int64 value, char *string, int radix ); char * _ui64toa( unsigned _int64 value, char *string, int radix ); wchar_t * _itow( int value, wchar_t *string, int radix ); wchar_t * _i64tow( __int64 value, wchar_t *string, int radix ); wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix ); Routine Required Header Compatibility _itoa <stdlib.h> Win 95, Win NT _i64toa <stdlib.h> Win 95, Win NT _ui64toa <stdlib.h> Win 95, Win NT _itow <stdlib.h> Win 95, Win NT _i64tow <stdlib.h> Win 95, Win NT _ui64tow <stdlib.h> Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value Each of these functions returns a pointer to string. There is no error return. Parameters value Number to be converted string String result radix Base of value; must be in the range 2 – 36 Remarks The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 bytes) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( – ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively. Generic-Text Routine Mappings TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _itot _itoa _itoa _itow Example /* ITOA.C: This program converts integers of various * sizes to strings in various radixes. */ #include <stdlib.h> #include <stdio.h> void main( void ) { char buffer[20]; int i = 3445; long l = -344115L; unsigned long ul = 1234567890UL; _itoa( i, buffer, 10 ); printf( "String of integer %d (radix 10): %s\n", i, buffer ); _itoa( i, buffer, 16 ); printf( "String of integer %d (radix 16): 0x%s\n", i, buffer ); _itoa( i, buffer, 2 ); printf( "String of integer %d (radix 2): %s\n", i, buffer ); _ltoa( l, buffer, 16 ); printf( "String of long int %ld (radix 16): 0x%s\n", l, buffer ); _ultoa( ul, buffer, 16 ); printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul, buffer ); } Output String of integer 3445 (radix 10): 3445 String of integer 3445 (radix 16): 0xd75 String of integer 3445 (radix 2): 110101110101 String of long int -344115 (radix 16): 0xfffabfcd String of unsigned long 1234567890 (radix 16): 0x499602d2 Data Conversion Routines See Also _ltoa, _ultoa
「已注销」 2015-09-06
  • 打赏
  • 举报
回复
UINT uNumber = 13572468; CString strNumber; strNumber.Format(TEXT("%u"), uNumber);
Techay 2015-09-05
  • 打赏
  • 举报
回复
引用 5 楼 VisualEleven 的回复:
CString::Format()就可以了。
试了,并不可以啊……
Eleven 2015-09-05
  • 打赏
  • 举报
回复
CString::Format()就可以了。
Techay 2015-09-05
  • 打赏
  • 举报
回复
引用 2 楼 u011001084 的回复:
format
试过了,在UNICODE情况下误差特别大
Techay 2015-09-05
  • 打赏
  • 举报
回复
引用 1 楼 mfmfmmf1 的回复:
这还不简单 先把UINT转为INT 然后再转CString呗
UINT肯定会爆INT,想好再回答
ArthurKingYs 2015-09-05
  • 打赏
  • 举报
回复
format
mfmfmmf1 2015-09-05
  • 打赏
  • 举报
回复
这还不简单 先把UINT转为INT 然后再转CString呗
schlafenhamster 2015-09-05
  • 打赏
  • 举报
回复
0x7FFF FFFF FFFF FFFF
RuiyuanZHOU 2015-09-05
  • 打赏
  • 举报
回复
使用CString的Format函数,格式字符串用 L"%lld" 试了一下,最大数为9223372036854775807
worldy 2015-09-05
  • 打赏
  • 举报
回复
unicode下,使用itoa肯定是错误的
worldy 2015-09-05
  • 打赏
  • 举报
回复
在MFC中把UINT转换为CString, 使用CString的Format函数,如果有问题,那肯定是楼主给格式串有问题,针对UINT,lz的注意值的最高位如果为1,则会被转为负数; 或者使用 wchar_t * _itow( int value, wchar_t *string, int radix );
zgl7903 2015-09-05
  • 打赏
  • 举报
回复
用 _ultot 或 _ultot_s
zwfgdlc 2015-09-05
  • 打赏
  • 举报
回复
数值很大吗?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧