title: c++ Function to format time_t as std::string: buffer length?
body: <p>I want a function that will take a time_t parameter and an arbitrary format string and format it.  I want something like this:</p>
  
  <pre><code>std::string GetTimeAsString(std::string formatString, time_t theTime)
  {
      struct tm *timeinfo;
      timeinfo = localtime( &amp;theTime);
  
      char buffer[100];
      strftime(buffer, 100, formatString.c_str(), timeinfo);
      std::string result(buffer);
      return result;
  }
  </code></pre>
  
  <p>However one problem I'm running into is the buffer length.  I was thinking of doing something like formatString * 4 as the buffer length.  But I guess you can't dynamically set the buffer length?  Maybe I could pick an arbitrarily large buffer? I'm a little stuck as to how to make it generic.</p>
  
  <p>How can I write a function to achieve this?</p>