Solved

Convert Unmanaged char to magaged string (String ^ ) in VC++. Net

Posted on 2010-09-10
6
1,122 Views
Last Modified: 2012-05-10
Hi,

I would like to convert unmanaged char to managed string in VC++ .net. I was able to convert char * to String^ using the below statement ,however I was not able to convert char to String^.

String ^ CXMLUtil::ConvertChartoString(const char *ch)
{
      String ^ strValue=gcnew String(ch);
      return strValue;
}

Please let me know how to convert unmanaged char to managed string String^.

Thanks
0
Comment
Question by:GouthamAnand
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648230
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648246
0
 

Author Comment

by:GouthamAnand
ID: 33648590
Hi ,

After including the code suggested by you, I got another error saying "Error      224      error C4980: '__box' : use of this keyword requires /clr:oldSyntax command line option". I dont want to change the command line to /clr:oldSyntax.

Please advise me.      
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648801
Use something else. Convert, ASCIIEncoding, ...  Can you show your code?
Simple constructor? That's from Unciode:
String^ szGreekAlpha = gcnew String( L'\x0319',5 );
http://msdn.microsoft.com/en-us/library/xsa4321w.aspx





0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 33664399
           wchar_t ch = 'x';
            String^ s = gcnew String(&ch);
and
            char c = 'y';
            String^ s2 = gcnew String(&c);


For both narrow and wide characters.  (Note the & - it won't compile without that for single characters)
0
 

Author Closing Comment

by:GouthamAnand
ID: 33977505
Thank you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now