title: C++ IRC Bot Buffer Error
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fstream&gt;
  #include &lt;pthread.h&gt;
  #include &lt;ostream&gt;
  #include &lt;unistd.h&gt;
  #include &lt;boost/array.hpp&gt;
  #include &lt;boost/algorithm/string/replace.hpp&gt;
  #include &lt;array&gt;
  #define NUM_THREADS 3
  
  void *Bot(void *threadid)
  {
   while(1)
   {
    using boost::asio::ip::tcp;
    try {
     std::ofstream store;
     boost::asio::io_service io_service;
     tcp::resolver resolver(io_service);
     tcp::resolver::query query("###########", "6667");
     tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
     tcp::resolver::iterator end;
     tcp::socket socket(io_service);
     boost::system::error_code error = boost::asio::error::host_not_found;
     while (error &amp;&amp; endpoint_iterator != end)
     {
      socket.close();
      socket.connect(*endpoint_iterator++, error);
     }
     if (error)
      throw boost::system::system_error(error);
     sleep(5);
     boost::system::error_code ignored_error;
     boost::asio::streambuf request;
     std::ostream send_stream(&amp;request);
     send_stream &lt;&lt; "USER Cribot * * :Cribot\r\nNICK Cribot\r\nJOIN #hide\r\nPRIVMSG #hide :
                Hello master, your wish is my command.\r\n";
     boost::asio::write(socket, request, ignored_error);
     while(1)
     {
      store.open("IRC.log", std::ios::app);
      static std::string lel;
      boost::system::error_code error;
      if (error == boost::asio::error::eof)
       break;
      else if (error)
       throw boost::system::system_error(error);
      boost::array&lt;char, 128&gt; buf;
      size_t len = socket.read_some(boost::asio::buffer(buf), error);
      if(lel == "PING")
      {
       boost::system::error_code ignored_error;
       boost::asio::streambuf request;
       std::ostream send_stream(&amp;request);
       send_stream &lt;&lt; "PONG\r\n";
       boost::asio::write(socket, request, ignored_error);
      }
      store.write(buf.data(), len); # THIS ENTERS NOTHING IN MY FILE
      std::cout.write(buf.data(), len); #THIS WORKS
      store.close();
     }
    } catch (std::exception &amp;e) {}
   }
  }
  
  int main()
  {
   pthread_t threads[NUM_THREADS];
   pthread_create(&amp;threads[1], NULL, Bot, (void *)1);
   pthread_join(threads[1], NULL);
   return 0;
  }
  </code></pre>
  
  <p>Hello, basically I'm making a simple IRC bot that sits in my channel and logs everything that happens, I made it, it works but my only issue is I can't write the chat into a file "store" but using the same code, I'm able to print what's coming from the IRC server</p>