问题
I have a problem in "Rad Studio 10 Seattle" where I am trying to get text input from a TEdit
object and I get a errormessage saying
E2034 Cannot convert 'UnicodeString' to 'string'
My code is as follows:
this->shopVar->addDog(edName->Text, StrToInt(edAge->Text), "male", "dogspecial");
This function addDog
takes (string, int, string, string)
When I try to send the text from the TEdit
object with edName->Text
I get the errormessage mentioned earlier.
My question is as follows, can i make a convertion on edName
from unicodestring to string or do I have to change the datatype of my parameterlist? If so, how do I do it?
I have been searching for this issue but have not found anything that is similar to my problem.
回答1:
You need to convert the UnicodeString
data to Ansi first, then pass that instead. The easiest way is to assign the UnicodeString
to an AnsiString
(or derivative) first, and then use its c_str()
method to get a char*
pointer, which std::string
will accept:
this->shopVar->addDog(AnsiString(edName->Text).c_str(), ...);
If possible, maybe consider rewriting your shopVar
class to use std::wstring
instead, then you can remove the Ansi conversion:
this->shopVar->addDog(edName->Text.c_str(), StrToInt(edAge->Text), L"male", L"dogspecial");
来源:https://stackoverflow.com/questions/34661481/convert-unicodestring-to-string-in-xrad-studio