0

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

5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by jonsca
0

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() );
2

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.

Votes + Comments
Thank you +rep
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.