title: What data type should I use as a buffer?
body: <p>I'm writing a simple chat server and I'm wondering what data type should I use for a buffer. I was thinking about <code>string</code> (which would be quite comfortable in my case), however many times I saw people writing that <code>string</code> should not be used as a buffer (better to use <code>vector&lt;char&gt;</code>) but is it always the case?</p>
  
  <p>In my program I would like to read some message from the client into a buffer, send that data to some other client and also store that message in database. I use SQLite so, with <code>string</code> (skipping db initialization) it would look like this:</p>
  
  <pre><code>std::string buffer;
  buffer.resize(1024);
  
  // read some data into the buffer
  socket.async_read_some(boost::asio::buffer(&amp;buffer[0], 1024),
      [this, self](boost::system::error_code ec, size_t length)
  {
      buffer.resize(length);
  
      // do some other things with buffer - send to another user ...
  
      std::string query = "INSERT INTO messages (message) VALUES (\"" + buffer "\")";
  
      sqlite3_exec(database, query.c_str(), sql_callback, NULL, &amp;err_msg);
  }
  </code></pre>
  
  <p>If I was to use <code>vector&lt;char&gt;</code> instead, I would firstly need to convert it to a string (or maybe there is another way?)</p>
  
  <p>So what should I use?</p>