Advertisement

07.02.2007 at 08:13PM PDT, ID: 22672074
[x]
Attachment Details

vc++ open file with openfiledialog

Asked by shinymoon in Microsoft Visual C++.Net

Tags: ,

I'm trying to open and read a file line by line and save each line to the array.

//this part is just openfiledialog and get the filename
OpenFileDialog^ fDialog = gcnew OpenFileDialog;
 fDialog->Title = "Open .mc File";
 fDialog->Filter = "MC FILES|*.mc";
fDialog->InitialDirectory = "c:\\";

if(fDialog->ShowDialog(this) == System::Windows::Forms::DialogResult::OK){
      MessageBox::Show(fDialog->FileName);
      ifs.open((fDialog->FileName)->c_str(), ifstream::ios_base);   //this line gives me an error
      while(ifs >> hex >> line){
                state.mem[i] = line;
                i++;
      }



If I use c_str(), it says error C2039: 'c_str' : is not a member of 'System::String'.
If I use ToCharArray() instead,  it says error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'const wchar_t *'      

Does anyone know how to do what I want?

Thank you in advance :)

Start Free Trial
 
Loading Advertisement...
 
[+][-]07.02.2007 at 11:53PM PDT, ID: 19409184

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C++.Net
Tags: openfiledialog, file
Sign Up Now!
Solution Provided By: marcodalzotto
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.03.2007 at 08:52PM PDT, ID: 19416452

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32