Conversion TCHAR -> wstring -> string -> String^ C++

I am away. From everything. Just pure programming. For three hours.

Approx 100 different web pages this evening. As always with C++: million ways to do stuff…

For the moment:

  • Initialize some TCHAR array:
  1. TCHAR s[1024];
  2. s=L”strings”;
  • Convert TCHAR array to wstring:
  1. wstring bob(&s[0]); //bob is the wstring variable name;
  • Convert wstring to string:
  1. string bill( bob.begin(), bob.end() ); //
  • Convert string to String^ (High class String with Garbage Collector and everything)
  1. String^ bill2 = gcnew String(bill.c_str());
  • Finally use String^ by MessageBox::Show():
  1. MessageBox::Show(bill2);

If any shorter way (shortcut), your response will be greatly appreciated. For the moment, ashamed about myself, because did not remember what is String^.

Birkas: ,

7 Atbildes to “Conversion TCHAR -> wstring -> string -> String^ C++”

  1. gardeedis Says:

    There are so many strings in here, that it sounds like Vairis version of the String Theory

  2. Joachim Says:

    THank you soooooooooooooooooo much!!! Rescude my day!!!

  3. Erik Kira Welander Says:

    From the bottom of my heart THANK YOU! I have been struggling with getting TCHAR to string for hours scavenging the deep roots of the nets like you until i found this post that actually works!

  4. dfs Says:

    thank you!

  5. dimsum204 Says:

    THANK YOU SO MUCH! BEEN STRUGGLING THE WHOLE DAY! Ur blog is definitely bookmarked!

Komentēt

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Mainīt )

Twitter picture

You are commenting using your Twitter account. Log Out / Mainīt )

Facebook photo

You are commenting using your Facebook account. Log Out / Mainīt )

Google+ photo

You are commenting using your Google+ account. Log Out / Mainīt )

Connecting to %s


%d bloggers like this: