Solved

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

Posted on 2009-04-06
5
1,257 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
ID: 24075272
char* pText = Marshal::StringToHGlobalAnsi( txtbox1->Text );
strcpy( c, pText );
Marshal::FreeHGlobal( pText );
0
 

Author Comment

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

Accepted Solution

by:
alb66 earned 250 total points
ID: 24077619
I forgot two cast...

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

Author Comment

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

Author Closing Comment

by:xuanspider
ID: 31566924
Anyhow, thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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