我有一个带有列表框的表单,其中包含四个单词的行。当我点击某一行时,这些单词应该在四个不同的文本框中显示出来。 到目前为止,我已经让所有东西都运作良好,但我在字符转换方面遇到了问题。
列表框中的字符串是UnicodeString,但strtok使用的是char[]。 编译器告诉我它“无法将UnicodeString转换为Char []”。这是我用于此的代码:
{
int a;
UnicodeString b;
char * pch;
int c;
a=DatabaseList->ItemIndex; //databaselist is the listbox
b=DatabaseList->Items->Strings[a];
char str[] = b; //This is the part that fails, telling its unicode and not char[].
pch = strtok (str," ");
c=1;
while (pch!=NULL)
{
if (c==1)
{
ServerAddress->Text=pch;
} else if (c==2)
{
DatabaseName->Text=pch;
} else if (c==3)
{
Username->Text=pch;
} else if (c==4)
{
Password->Text=pch;
}
pch = strtok (NULL, " ");
c=c+1;
}
}
我知道我的代码看起来不好看,实际上非常糟糕。 我只是在学习C ++编程。
我该怎么转换它?