title: Output to a selected file C++ Visual Studio 2015
body: <p>I need to output text from a textBox into a text file selected in a Save File Dialog.  My code is below.  I also need to write out the address of the file.</p>
  
  <pre><code>  private: System::Void saveToolStripMenuItem1_Click(System::Object^  sender, 
       System::EventArgs^  e)
    {
       SaveFileDialog saveFile;
       ofstream ofs;
       saveFile.ShowDialog(); //returns a DialogResult value (DialogResult.OK)
       string str = marshal_as&lt;string&gt;(saveFile.FileName); //file name
       ofs.open(str);
  
       if (str != "") //if a file is selected
       {
          ofs &lt;&lt; "TestMessage 1, 2" &lt;&lt; endl;
          ofs &lt;&lt; str; //Displays current file name
          ofs &lt;&lt; conc-&gt;GetConc(str, txtDisplay) &lt;&lt; endl;
          ofs &lt;&lt; marshal_as&lt;string&gt;(conc-&gt;GetConc(str, txtDisplay)) &lt;&lt; endl;
          ofs.close(); 
       }
       else
          MessageBox::Show("No file is selected for output.");
    }
  </code></pre>
  
  <p>So far I think what I've got is working.  However I still need to be able to get output from the textbox.  I've tried using something like the following, but it's not working.  <strong>Note: this would go just before "ofs.close();"</strong></p>
  
  <pre><code>    ofs &lt;&lt; txtDisplay-&gt;ToString() &lt;&lt; endl;
  </code></pre>
  
  <p>I'm thinking the problem is with my <strong>GetConc</strong> method.  Below are the header and body for the method.  Am I returning the wrong thing?</p>
  
  <pre><code>string GetConc(string stringEntry, TextBox ^ tb);//HEADER
  string Concordance::GetConc(string stringEntry, TextBox ^ tb)//BODY
  {
     string s = stringEntry + "   ";
     String ^s2 = gcnew String(s.c_str());
     // add stringEntry to display string + "   "
     // for
     // if found, add iter-&gt;second 
     int count = 0;
     map &lt;string, vector&lt;int&gt;&gt;::iterator iter;
  
     for (auto iter = m.cbegin(); iter != m.cend(); iter++)
     {
     string test = iter-&gt;first;
     if (test == stringEntry)
     {
        vector&lt;int&gt;::iterator i;
        for (auto i = iter-&gt;second.cbegin(); i != iter-&gt;second.cend(); i++)
        {
           s2 += *i;
           if (i + 1 != iter-&gt;second.cend())
              s2 += ",";
        }
     }
  }
  tb-&gt;Text += s2 + "\r" + "\n";
  return s;
  }
  </code></pre>