我正在尝试从C ++客户端向Java服务器发送“字符串”。在服务器端,用户名是String
。在我的IDL中,它是WStringValue
,因此我必须从我的客户端发送用户名WStringValue
。以下代码适用于双方:
const CORBA::WChar* usern = (wchar_t*)L"Chuck Norris";
CORBA::WStringValue* username = new CORBA::WStringValue(usern);
但我想从键盘上获取用户名...现在,我的问题是如何将char[]
转换为Wchar*
?在我的实验之后,似乎编码也存在问题..
cout << "Please type your Username: " << endl;
fgets(input, MAX_LINE, stdin);
strcpy(username, input);
const CORBA::WChar* usern = (wchar_t*)username;
CORBA::WStringValue* username = new CORBA::WStringValue(usern);
我该怎么做?
答案 0 :(得分:2)
您可以尝试以下方式执行此操作:
std::string str (input);
std::wstring ws;
ws.assign (str.begin(), str.end());
const CORBA::WChar* usern = ws.c_str (); // warning: it will live only while ws lives