如何在C ++构建器列表框中显示ushort char数组? [英] How do I display a ushort char array in a C++ builder listbox?

查看:85
本文介绍了如何在C ++构建器列表框中显示ushort char数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我使用的是C ++ Builder。我在类中有一个方法,可以将文件加载到各种结构中。结构中的一个字段定义为,例如:



First, I am using C++ Builder. I have a method in a class that loads a file into various structs. One of the fields in the struct is defined as, for example:

typedef unsigned short namechar;

struct MyStruct {
int id;
namechar name[32];
};





代码使用for循环遍历所有结构以将名称字段显示到ListBox中但是:





The code uses a for loop to go through all of the structs to display the name field into a ListBox but:

for (int i = 0; i < MyStructArray.size(); i++)
{
   ListItem->Items->Add(MyStructArray[i].name);
}





不起作用。我尝试了很多不同的方法,并花了最后几个小时进行谷歌搜索,但仍然不知道如何将名称字段转换为在ListBox中显示。



< b>我尝试了什么:



我已经尝试了我能想到的一切。 namechar数组是UTF16,C ++ Builder需要UnicodeString,据我所知,它是同一个东西。我对此感到难过并且已经持续了近6个小时并且一无所知。



does not work. I've tried many different approaches and spent the last several hours doing google searches and still have no idea how to convert the name field to show in the ListBox.

What I have tried:

I have tried everything I can think of. The namechar array is UTF16 and C++ Builder require UnicodeString, which, as far as I know, are the same thing. I am stumped on this and have been at it for nearly 6 hours and am clueless.

推荐答案

好的,我得到了它的工作。我使用的解决方案是:



Ok, I got it to work. The solution I used is:

for (int i = 0; i < a001.size(); i++)
{
	String s = (wchar_t *) a001[i].name;
	ListItem->Items->Add(s);
}


这篇关于如何在C ++构建器列表框中显示ushort char数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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