wchar的int问题 [英] problems with int to wchar

查看:107
本文介绍了wchar的int问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct RCDENTRY
{
    WCHAR wszRcdInd[4];
    WCHAR wszTag[1];
};
.....
int nRcdNum = listbox.GetItemCount();    // CListBox
RCDENTRY *re = new RCDENTRY[nRcdNum];
...
for (int i = 0; i < nRcdNum; i++)
{
    ...
    _itow_s(i, re[i].wszRcdInd, sizeof(re[i].wszRcdInd], 10);    // this leads the program aborting
   ...
}


有人可以帮忙吗?
在此先感谢.


Anyone could help?
Thanks in advance.

推荐答案

sizeof返回以字节为单位的大小,但是_itow_s要求以字符为单位的大小.所以用
sizeof returns the size in bytes but _itow_s requires the size in characters. So use
sizeof(re[i].wszRcdInd]) / sizeof(WCHAR)



wszRcdInd的大小为4个字符,可以容纳从-99到999的十进制数字字符串,后跟NULL字符.因此,您还应确保列表框中最多包含999个项目.



The size of wszRcdInd is 4 characters which can hold decimal number strings from -99 to 999 with trailing NULL character. So you should also ensure that your list box will not contain more than 999 items.


这篇关于wchar的int问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆