如何使用_wtoi将wchar_t转换为int?

zetifree 2009-05-26 07:30:21
看到一些资料提到可以用wtoi将wchar_t转换为int,我试了试,每次输出都是"0"。这个程序为什么不行呢?
是不是我用wtoi有问题?


#include <iostream>
using namespace std;
int main()
{
wchar_t a;
cin>>a;
int b=_wtoi(&a);
cout<<b<<endl;
return 0;
}
...全文
2977 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyflyrain 2010-10-08
  • 打赏
  • 举报
回复

char *sz = "anihoifh";
wchar_t *wsz;
wsz = AnsiToUnicode(sz);
TRACE(L"wsz = %s\n",wsz);

wchar_t *wch = L"andy";
sz = UnicodeToAnsi(wch);
TRACE(L"UnicodeToAnsi(wch) = %s \n", AnsiToUnicode(sz));
UINT n = 5;

swprintf( wsz, L"%d",n);
andyflyrain 2010-10-08
  • 打赏
  • 举报
回复
char *sz = "anihoifh";
wchar_t *wsz;
wsz = AnsiToUnicode(sz);
TRACE(L"wsz = %s\n",wsz);

wchar_t *wch = L"andy";
sz = UnicodeToAnsi(wch);
TRACE(L"UnicodeToAnsi(wch) = %s \n", AnsiToUnicode(sz));
UINT n = 5;

swprintf( wsz, L"%d",n);
乔乔公爵 2009-05-27
  • 打赏
  • 举报
回复
你需要使用Visual Studio .NET 2003或2005 2008
VC6太旧了,这些东西都支持得不好。毕竟是10年前的古董了,不能对它要求太高
Darkneece 2009-05-27
  • 打赏
  • 举报
回复
本来就是把数字字符串转成整形的,你转英文和中文做什么
zetifree 2009-05-26
  • 打赏
  • 举报
回复
我在VC++ 6.0试了试,不可以啊。
输入英文字母,全部输出0.
中文无效~~
乔乔公爵 2009-05-26
  • 打赏
  • 举报
回复

#include <iostream>

using namespace std;
int main()
{
wchar_t a[32];
wcin>>a;
int b=_wtoi(a);
wcout<<b<<endl;
return 0;
}


你的变量a,应该是字符数组,而不是字符型
qq675927952 2009-05-26
  • 打赏
  • 举报
回复

int _wtoi(
const wchar_t *str
);

str
String to be converted.

Each function returns the int value produced by interpreting the input characters as a number. The return value is 0 for atoi and _wtoi, if the input cannot be converted to a value of that type.

33,322

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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