Conversion from System::String to char*

Started by
4 comments, last by hammerstein_02 20 years ago
I have recently begun to work with Visual C++.NET 2003, and as such now have the nice forms designer available to me. As I am not a complete novice at C++ programming, I have decided my first app will be a Mysql interface for a website I am designing. I figured out how to get the Mysql API to compile with my program, but I as I am using managed code I have System::Strings passed to my Mysql interface class. mysql_real_connect() only accepts char* though. I have begun looking, and the simplest solution I found was if( str->Length <= 255){ for( int i = 0; iLength;i++) s = str->get_Chars(i); } There was another one but it used all sorts of functions included dllImport or something, which looked far too complex for what I was actually trying to acheive. So I was wondering if anybody on here had an idea of what I need to do to do this conversion. Oh yeah and it is DEFINATLEY a char* not a Char. Many thanks =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=
Advertisement
string asd = "asd";
char *a = new char[asd.length()+1];

strcpy(a,asd.c_str());
aa sry i dident read all =)
http://support.microsoft.com/?kbid=311259
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasstopic.asp


copy or copyTo
Many thanks, that looks like what I am after. I spent many hours trying different combinations and could only find Char conversions, methinks I was looking in the wrong place. But your help is greatly appreciated.

This topic is closed to new replies.

Advertisement