Hello all
I have a problem.I am trying to convert 'System:tring ^' to 'const char *' but i don`t know how.
can some one please help me?

I use VC++ 2005
I need to open files with extension .wav

my code is:

public:System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 
{   
 OpenFileDialog open;
open.Title = "Select Wave File";
open.Multiselect = true;
open.CheckFileExists = true;
open.Filter = "Audio Files (*.wav)|*.wav";
open.FilterIndex = 2;
open.InitialDirectory="C:";
				

if (open.ShowDialog()==System::Windows::Forms::DialogResult::OK )
{

ifstream waveFile (open.FileName);// my error is here
.

if I use for example
ifstream waveFile("test.wav") i get no errors

what can I do if I want to open *.wav

Recommended Answers

All 5 Replies

Does system::string have anything in common with std::string ?

In which case, perhaps it has a method like this.

ifstream waveFile ( open.FileName.c_str() );

You can use one of the Marshal::StringToHGlobalAnsi/Auto/Uni methods to copy the string into unmanaged memory, and then clean up with Marshal::FreeHGlobal when you're done.

There's an example here that does exactly that.

commented: Thank you +rep +0

Thank you gashtio. It is working perfect now

C# language ,,this is CPP forum

C# language ,,this is CPP forum

Meet C++/CLI. We keep it out in the woodshed but it's a member of the family nonetheless. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.