title: When should std::string be used over character arrays?
body: <p>I sit around and think about whether or not I should be using <code>const char*</code> or <code>const std::string&amp;</code> pretty often when I'm designing class interfaces and when it comes down to it, I often feel like there's 6 in one hand with half a dozen in the other.</p>
  
  <p>Take the following two function prototypes:</p>
  
  <pre><code>void foo(const char* str);
  void foo(std::string str);
  </code></pre>
  
  <p>If the <code>foo</code> function were to store a string, I would say the second is a better option due to the ability to pass a string and utilize move semantics where possible. However, if <code>foo</code> only needed to read the string, would the <code>const char*</code> solution be better?</p>
  
  <p>On a performance perspective, a temporary <code>std::string</code> wouldn't need to be created. However, calling the function with an already existing string as an argument looks obtrusive: <code>foo(mystr.c_str())</code>. Worse yet, if more advanced operations need to be done on the array at some point down the road or if a copy should be stored, the interface then has to change.</p>
  
  <p>So my questions is this:</p>
  
  <p>Are there well defined, either personal or otherwise, conventions that rule when <code>std::string</code> or <code>const char*</code> is a better choice? Furthermore, when starting a new project, is it best to be consistent with usage or just take whichever one fits the current chunk of code best?</p>