title: C++ cout printing slowly
body: <p>I noticed if I print out a long string(char*) using cout it seems to print 1 character at a time to the screen in Windows 7, Vista, and Linux(using putty) using Visual C++ 2008 on Windows and G++ on Linux. Printf is so much faster I actually switched from cout to printf for most printing in a project of mine. This is confusing me because this <a href="https://stackoverflow.com/questions/896654/cout-or-printf-which-of-the-two-has-a-faster-execution-speed-c">question</a> makes it seem like I'm the only one having this issue.</p>
  
  <p>I even wrote a cout replacement that looks like it beats the pants off of cout on my comp -</p>
  
  <pre><code>class rcout
  {
  public:
      char buff[4096];
      unsigned int size;
      unsigned int length;
  
      rcout()
      {
          size = 4096;
          length = 0;
          buff[0] = '\0';
      }
  
      ~rcout()
      {
          printf("%s", buff);
      }
  
      rcout &amp;operator&lt;&lt;(char *b)
      {
          strncpy(buff+length, b, size-length);
          unsigned int i = strlen(b);
          if(i+length &gt;= size)
          {
              buff[size-1] = '\0';
              printf("%s", buff);
              b += (size-length) -1;
              length = 0;
              return (*this) &lt;&lt; b;
          }
          else
              length += i;
          return (*this);
      }
  
      rcout &amp;operator&lt;&lt;(int i)
      {
          char b[32];
          _itoa_s(i, b, 10);
          return (*this)&lt;&lt;b;
      }
  
      rcout &amp;operator&lt;&lt;(float f)
      {
          char b[32];
          sprintf_s(b, 32, "%f", f);
          return (*this)&lt;&lt;b;
      }
  };
  
  int main()
  {
      char buff[65536];
      memset(buff, 0, 65536);
  
      for(int i=0;i&lt;3000;i++)
          buff[i] = rand()%26 + 'A';
  
      rcout() &lt;&lt; buff &lt;&lt; buff &lt;&lt;"\n---"&lt;&lt; 121 &lt;&lt;"---" &lt;&lt; 1.21f &lt;&lt;"---\n";
      Sleep(1000);
      cout &lt;&lt; "\n\nOk, now cout....\n\n";
      cout &lt;&lt; buff &lt;&lt; buff &lt;&lt;"\n---"&lt;&lt; 121 &lt;&lt;"---" &lt;&lt; 1.21f &lt;&lt;"---\n";
      Sleep(1000);
      cout &lt;&lt; "\n\nOk, now me again....\n\n";
      rcout() &lt;&lt; buff &lt;&lt; buff &lt;&lt;"\n---"&lt;&lt; 121 &lt;&lt;"---" &lt;&lt; 1.21f &lt;&lt;"---\n";
      Sleep(1000);
  
      return 0;
  }
  </code></pre>
  
  <p>Any ideas why cout is printing so slowly for me?</p>