Help with the ifstream function in C++
<p>I've read a lot of tutorials and can not really find anything comprehensive on this subject. </p>

<p>I had written the following code to do one function:</p>

<pre><code>#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

using namespace std;

ifstream ReadFile( ifstream&amp; openInputFile, string&amp; sLine, int&amp; chgLine );


int main()
{
    int chgLine;
    string MyFile, sLine, 
    sFile = "test.txt";

    cout &lt;&lt; "Enter a file: ";
    cin &gt;&gt; MyFile ;

    ifstream openInputFile;


    if ( MyFile != sFile )    // file must be 'hello.cpp' to proceed
    {
       cout &lt;&lt; "Error";
       exit(0);
    }
                         // if correct file is entered print the contents of it

        ReadFile( openInputFile, sLine, chgLine );

    system("pause");
    return 0;
}

ifstream ReadFile( ifstream&amp; openInputFile, string&amp; sLine, int&amp; chgLine )
{ 

       while ( getline ( openInputFile, sLine ) )
       {
      if ( sLine.length() == 0 ) continue;  // to proceed

             for ( chgLine = 0; chgLine &lt; sLine.length(); chgLine++ )
           {
                if ( sLine[chgLine] &gt;= 97 &amp;&amp; sLine[chgLine] &lt;= 122 || sLine[chgLine] &gt;= 65 &amp;&amp; sLine[chgLine] &lt;= 90  )
                {
                     cout &lt;&lt; sLine[chgLine];
                }

             }
        }
}
</code></pre>

<p>But now I've decided to break all of this up into three functions that do what I want separately, and then call them from the <code>main()</code> function. </p>

<p>The first function opens the file:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

ifstream openInputFile()

{
       // use a pointer..return a pointer
       // ifstream definition is the challenge
  ifstream *fp;
  //fp = new ifstream openInputFile;
  return openInputFile;

}

int main()

{
    cout &lt;&lt; "Hello, world!" &lt;&lt; endl;

    system("pause");
    return 0;
}
</code></pre>

<p>I get stuck trying to return a pointer. I don't understand what I'm doing wrong. How can I get the last bit of code to work? And how does one return a pointer with <code>ifstream</code> if it has the function's type?</p>
