cannot convert from 'System::String ^' to 'System::String'

FILE * myfile1 = fopen ( System::String(textBox1->Text) ,"rb" );

error C2440: '<function-style-cast>' : cannot convert from 'System::String ^' to 'System::String'

How do i convert this properly?
use the following conversion.
String^ str3 = gcnew String(str.c_str())

http://msdn.microsoft.com/en-us/library/ms235219.aspx
You could use the Marshal conversion ...
example :
1
2
3
4
5
6
7
8
9
#include <msclr\marshal_cppstd.h>

using namespace msclr::interop;
using namespace std;
using namespace System;

System::String ^ fileText = textBox1->Text;

std::string converted_fileText = msclr::interop::marshal_as< std::string >(fileText);
Last edited on
Thank you anmol2701 & UtherPendragon17 both of your answers is correct.

My code looks like this now:

1
2
3
4
5
6
7
8
9
10
11
#include <msclr\marshal_cppstd.h>

using namespace msclr::interop;
using namespace std;
using namespace System;

System::String ^ fileText = textBox1->Text;

std::string converted_fileText = msclr::interop::marshal_as< std::string >(fileText);

FILE * myfile1 = fopen ( converted_fileText.c_str() ,"rb");


Topic archived. No new replies allowed.