字符串和数字之间的转换(Unicode)

CString str ;

str = _T("1234");
int i = _ttoi(str);

float f = _tstof(str);

**************************

数字转wchar_t
wchar_t c[10];

int num = 100;
_itow_s(num , c,10,10);
wstring str(c);

******************************

wstring to int
_wtoi(str.c_str());

******************************

如果你准备使用 Unicode 字符,你应该用_ttoi(),它在 ANSI 编码系统中被编译成_atoi(),而在 Unicode 编码系统中编译成_wtoi()。你也可以考虑使用_tcstoul()或者_tcstol(),它们都能把字符串转化成任意进制的长整数(如二进制、八进制、十进制或十六进制),不同点在于前者转化后的数据是无符号的(unsigned),而后者相反。看下面的例子:

CString hex = _T("FAB");
CString decimal = _T("4011");
ASSERT(_tcstoul(hex, 0, 16) == _ttoi(decimal));

原文地址:https://www.cnblogs.com/hbf369/p/2314634.html