0

I want to know how I can convert string str = "whatever" to wchar_t so that the string can be stored as wchar_t chResponse[] = ...(converted from string)..

I am trying the following code:

string str = "whatever";
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8conv;
auto w_result = utf8conv.from_bytes(str); // convert utf8 to wchar_t
wchar_t chResponse[] = w_result;

Its giving me this error:

error C2075: 'chResponse' : array initialization needs curly braces
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
CarbonD1225
  • 851
  • 6
  • 24
  • 39
  • 3
    Look into `std::wstring_convert`. – chris Feb 12 '13 at 01:28
  • can you please give me an example. I am trying the following code: `string str = "whatever"; std::wstring_convert> utf8conv; auto w_result = utf8conv.from_bytes(str); // convert utf8 to wchar_t wchar_t chResponse[] = w_result;` Its giving me this error: `error C2075: 'chResponse' : array initialization needs curly braces` – CarbonD1225 Feb 12 '13 at 01:40
  • 1
    Look to your right. This has been asked a million times. – Lightness Races in Orbit Feb 12 '13 at 01:44
  • @user1319424, You need to copy the result into your buffer if you want it non-const. – chris Feb 12 '13 at 01:45
  • I am so confused. Can someone please just tell me how to convert this. I am not able to understand where m i going wrong. Can you please just write a snippet for the conversion?? – CarbonD1225 Feb 12 '13 at 01:52

0 Answers0