Overload cin to take ifstream instead of char* fname?
<p>I am trying to create a file manipulator so when I <code>cin &gt;&gt; filename</code> it will read the file and cout the value... of course I am going add more stuffs but I would like to proceed with the basic of getting the content of the file.</p>

<p>What I wanna achieve is by cout prompting user for a textfile name, then when he enter, I will do another <code>cin &gt;&gt; readfile</code> on next line of code then the compiler will run the operator overload and cout the content.</p>

<p>How do I achieve it. Below is my code. </p>

<p>Question is instead of taking in <code>char* fname</code>, can I send ifstream in instead</p>

<p>so I can do something like</p>

<pre><code>ifstream infile(filename.c_str());
cin &gt;&gt; infile
</code></pre>

<p>Below is my current code</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include "point2d.cpp"
#include "line2d.cpp"
#include &lt;iomanip&gt;

using namespace std;

struct myself
{
    string myname;
};

istream &amp;operator&gt;&gt; (istream &amp;stream, myself &amp;myself )
{
    cout &lt;&lt; "Enter my name";
    stream &gt;&gt; myself.myname;
    return stream;
}

istream &amp;operator&gt;&gt; (istream &amp;in, char* fname)
{
    ifstream inFile;
    inFile.open(fname);
    char ch1;
    while (inFile.get(ch1))
    {
        cout &lt;&lt; ch1;
    }
}

int main()
{
    string filename;
    cout &lt;&lt; "Enter file name: ";
    cin &gt;&gt; filename;

    // was thinking of
    // ifstream infile(filename.c_str());
    // then read infile with cin

    //how do i cin filename and read its content.     
    return 0;
}
</code></pre>
