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));

相关文章:

  • 2022-02-08
  • 2021-10-19
  • 2021-09-19
  • 2022-01-07
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
猜你喜欢
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-07-22
  • 2021-08-21
相关资源
相似解决方案