Solved

How to convert string to char[] in C++ 2008

Posted on 2009-04-06
5
1,253 Views
Last Modified: 2012-05-06
I have a array char c[256]

How to convert txtbox1->Text to c[]?

Thank you. The environment is c++2008
0
Comment
Question by:xuanspider
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:alb66
Comment Utility
char* pText = Marshal::StringToHGlobalAnsi( txtbox1->Text );
strcpy( c, pText );
Marshal::FreeHGlobal( pText );
0
 

Author Comment

by:xuanspider
Comment Utility
IntPtr can not convert to char *, my environment is .net 2008
0
 
LVL 19

Accepted Solution

by:
alb66 earned 250 total points
Comment Utility
I forgot two cast...

char* pText = (char*)Marshal::StringToHGlobalAnsi( txtbox1->Text );
strcpy( c, pText );
Marshal::FreeHGlobal( (IntPtr)pText );
0
 

Author Comment

by:xuanspider
Comment Utility
I'm sorry that still cannot, same error. Please note that the environment is C# express 2008
0
 

Author Closing Comment

by:xuanspider
Comment Utility
Anyhow, thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

8 Experts available now in Live!

Get 1:1 Help Now