title: Function to Return output from text file
body: <p>I am a complete C++ newbie (Python is all i know) and i am trying to figure out what i am doing wrong. This tutorial shows me how to output a text file (<a href="http://www.cplusplus.com/doc/tutorial/files/" rel="nofollow">http://www.cplusplus.com/doc/tutorial/files/</a>)</p>
  
  <pre><code>// reading a text file
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main () {
    string line;
    ifstream myfile ("example.txt");
    if (myfile.is_open())
    {
      while ( myfile.good() )
      {
        getline (myfile,line);
        cout &lt;&lt; line &lt;&lt; endl;
      }
      myfile.close();
    }
  
    else cout &lt;&lt; "Unable to open file"; 
  
    return 0;
  }
  </code></pre>
  
  <p>And then when i try to apply this it gives me a <b>Segmentation error</b></p>
  
  <pre><code>// basic file operations
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  string WriteTXT( string DATA , string F_NAME)
  {
      ofstream myfile;
      myfile.open (F_NAME.c_str());
      myfile &lt;&lt; DATA;
      myfile.close();
  }
  
  string ReadTXT( string F_NAME )
  {
      string line;
      ifstream myfile (F_NAME.c_str());
      if (myfile.is_open())
      {
          while ( myfile.good() )
          {
              getline (myfile,line);
              cout &lt;&lt; line &lt;&lt; endl;
          }
          myfile.close();
      }
      else cout &lt;&lt; "Unable to open file"; 
  }
  
  int main () {
    WriteTXT("12345","example.txt");
    ReadTXT("example.txt");
    return 0;
  }
  </code></pre>
  
  <p>What on earth?</p>