Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-10
6
Medium Priority
?
1,149 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 45

Accepted Solution

by:
AndyAinscow earned 375 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

886 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