[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

wstring -> String^ conversion

I need to convert a wstring to an ansi string(String^)...

wstring message = "message";
wstring caption = "caption";
MessageBox::Show(message, caption) <---- doesnt work as is

Any help appreciated.
0
kingofnines
Asked:
kingofnines
  • 2
1 Solution
 
pgnatyukCommented:
But MessageBox::Show expects String^, so why you send wstring?
Sorry, I'm not on Windows right now. So check:
String^ s = gcnew String(message.c_str());

or:
#include
wchar_t __pin *p = PtrToStringChars(message.w_str());

http://support.microsoft.com/kb/311259
0
 
felipe_schauenburgCommented:
try these both and let know if any works

wstring message = L"message";
string stdString(message.begin(), message.end());

OR

wstring message = L"message";
string stdString = message.c_str();
0
 
pgnatyukCommented:
@felipe_schauenburg: please read carefully. The question is about String^. Not about std::string. Your conversion is wrong anyway.
0
 
kingofninesAuthor Commented:
String^ s = gcnew String(message.c_str());

Worked great. Thank you. The example I gave was simplified for ease of reading. The message I am building for the message box is made up from several variables some of which are wstrings.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now