title: C++ variable arguments with std::string only
body: <p>I'm trying to create a function that takes a variable amount of std::string arguments and formats a string with it.</p>
  
  <p>Example:</p>
  
  <pre><code>Test::formatLine(const string::format, ...)
  {
      const std::string buffer;
  va_list args;
  va_start(args, format);
  vsprintf(buffer.c_str, format.c_str, args);
  va_end(args);
  cout &lt;&lt; buffer &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Compiling this snippet errors:</p>
  
  <pre><code>Error   1   error C3867: 'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::c_str': function call missing argument list; use '&amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::c_str' to create a pointer to member
  </code></pre>
  
  <p>What I want to achieve:</p>
  
  <pre><code>Test t = Test();
  t.formatLine("Hello %s!", "monsieur");
  </code></pre>
  
  <p>should print <code>Hello monsieur!</code></p>
  
  <pre><code>t.formatLine("Hello %s %s! How %s you today?", "good", "sir", "are");
  </code></pre>
  
  <p>should print <code>Hello good sir! How are you today?</code></p>
  
  <p>Is it even possible to use <code>va_list</code> and <code>vsprintf</code> with <code>std::string</code> only, avoiding <code>char buffer[size]</code>?</p>
  
  <p>Working example (so far) with fixes suggested by Igor, using buffer:</p>
  
  <pre><code>void Test::formatLine(string format, ...)
  {
      char buffer[256];
      va_list args;
      va_start(args, format);
      vsprintf_s(buffer, format.c_str(), args);
      va_end(args);
      cout &lt;&lt; buffer &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Using <strong>Igor Tandetnik</strong>'s suggestion and sample code I finally got a working example that does not use char buffer[size]:</p>
  
  <pre><code>void Test::formatLine(string format, ...)
  {
      vector&lt;char&gt; buf(256);
      va_list args;
      va_start(args, format);
      vsnprintf_s(&amp;buf[0], buf.size(), buf.size() + strlen(format.c_str()), format.c_str(), args);
      va_end(args);
      cout &lt;&lt; &amp;buf[0] &lt;&lt; endl;
  }
  </code></pre>