title: How to hand a file path (text box value) to a file reading function in c++?
body: <p>I created a file chooser for windows it returns me a  chosen file path. I want to read the given file but I do not know how to pass the file path to the right function.</p>
  
  <p>File <code>Form1.h</code> I have a button action and inside of it I can get <code>openFileDialog1-&gt;FileName</code> but  I  do not know how to pass this variable to a <code>readFile()</code> function inside of <code>main.cpp</code> file.</p>
  
  <p>I created a method to return the path:</p>
  
  <pre><code>    System::String^ filePath;
  ....    
      private: System::String^ getPath() { return filePath; }
  </code></pre>
  
  <p>Here is the file-pickers code:</p>
  
  <pre><code>private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                Stream^ myStream;
                OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
  
                openFileDialog1-&gt;InitialDirectory = "c:\\";
                openFileDialog1-&gt;Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog1-&gt;FilterIndex = 2;
                openFileDialog1-&gt;RestoreDirectory = true;
  
                if ( openFileDialog1-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK ){
                  if ( (myStream = openFileDialog1-&gt;OpenFile()) != nullptr ){
                  // Insert code to read the stream here.
                   textBox1-&gt;Text = openFileDialog1-&gt;FileName; //text box displays the chosen path 
  
                    myStream-&gt;Close();
                  }
                }
           }
  </code></pre>
  
  <p>The variable is set on button click:</p>
  
  <pre><code>private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
              filePath = textBox1-&gt;Text;
           }
  </code></pre>
  
  <p>How to call the return methods in my <code>main.cpp</code>:</p>
  
  <pre><code>#include "stdafx.h"
  #include "Form1.h"
  
  using namespace main;
  using namespace std;
  
  [STAThreadAttribute]
  int main(array&lt;System::String ^&gt; ^args)
  {
      // Enabling Windows XP visual effects before any controls are created
      Application::EnableVisualStyles();
      Application::SetCompatibleTextRenderingDefault(false); 
  
      // Create the main window and run it
      Application::Run(gcnew Form1());
  
      System::String^ p1 = /*Something missing her?*/getPath1(); //I am guessing it should look like this...
      return 0;
  }
  </code></pre>