how do i write an overload operator>> function of class string?
<pre><code>class string 
{ 
  public: 
        friend istream&amp; operator &gt;&gt; ( istream&amp; is, string&amp; str); 
  private: 
        char *m_data; 
}; 

int main() 
{ 
  string str; 
  freopen("in.txt","r",stdin); 
  while( cin &gt;&gt; str) 
  { 
      cout &lt; &lt; str &lt; &lt; endl; 
  } 
  return 0; 
}
</code></pre>

<p>the content of in.txt are:</p>

<pre><code>asdfsfgfdgdfg
</code></pre>

<p>in the overload function, i use <code>is.get()</code> to read those charaters one by one,but program jump out the circle when cin finish,that means cout will not run. on the other way,i try <code>getchar()</code> instead, but it can not jump out the circle.</p>

<p>question: is there any wrong in my idea towards this function? or there is another better way to fulfill. thx :)</p>

<p>=========================================================================================
new edit:
here my code:
@Artem Barger
code detail</p>

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

namespace Str

{
    class string
    {
    public:
        string():k(0){}

    friend bool operator &gt;&gt; ( std::istream&amp; is, string&amp; str)
    {
        int size = 100;
        char m;

        if( (m = getchar()) &amp;&amp; m == -1)
            return false;

        str.m_data = new char[size];

        do
        {
            if( str.k == size)
            {
                size *= 2;
                char *temp = new char[size];
                for( int j = 0; j &lt; str.k; ++j)
                {
                    char *del = str.m_data;
                    temp[j] = *str.m_data++;
                    delete del;
                }
                str.m_data = temp;
                temp = NULL;
            }

            str.m_data[str.k++] = m;
        }while( (m = getchar()) &amp;&amp; m != -1);

        return true;
    }

    friend void operator &lt;&lt; ( std::ostream&amp; os, string&amp; str)
    {
        os &lt;&lt; str.m_data;
        str.k = 0;
        delete []str.m_data;
    }

private:
    char *m_data;
    int k;
};
}


using namespace Str;
int main()
{

string str;

while( std::cin &gt;&gt; str)
{
    std::cout &lt;&lt; str;
}

return 0;
}
</code></pre>

<p>still have some problem in the content of</p>

<pre><code>do
{
}while();
</code></pre>
