我有一个包含四个单词行的列表框.当我点击一行时,应在四个不同的文本框中看到这些单词.到目前为止,我已经完成了所有工作,但我遇到了字符转换的问题.列表框中的字符串是UnicodeString,但strtok使用char [].编译器告诉met无法将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;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我的代码看起来不太好,实际上非常糟糕.我只是在学习一些C++编程.谁能告诉我如何转换这个?