title: How to custom ostream c++
body: <p>i have a class:</p>
  
  <pre><code>class Y{
     public:
         int x;
         Y();
  };
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>int main(){
      Y y;
      y.x = 10;
      y &lt;&lt; mystream;
  
      return 0;
  }
  </code></pre>
  
  <p>I just wanna to cause any action when <code>y&lt;&lt;mystream</code> is typed.
  I tried in my class header like those:</p>
  
  <pre><code>friend Y mystream(Y y);
  friend ostream mystream(ostream o, Y y)
  </code></pre>
  
  <p>And etc. but nothing didn't work. Any ideas to custom this stream?</p>
  
  <p>Best regards!</p>