Solved

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

Posted on 2010-09-10
6
1,129 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

21 Experts available now in Live!

Get 1:1 Help Now