Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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];
};


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


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.
Posted
Updated 5-Jul-17 14:38pm
v2
Comments
Patrice T 5-Jul-17 20:49pm    
Make sure UTF16 and UnicodeString are the same thing. May get a surprise.

1 solution

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);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900