title: Interchanging const char* and std::string
body: <p>I am refactoring an old C library, and am currently changing the external API so that it uses std::string instead of const char*.</p>
  
  <pre><code>ColumnType Table::getColType(const char *name) const
  {
      int id = getColumnId(name) ;
      return getColType(id) ;
  }
  
  and
  
  int Table::getColumnId (const char * col_name) const
  {
      unsigned int i = 0;
  
      while ((i &lt; m_table.num_cols) &amp;&amp; (strcmp(m_table.cols[i]-&gt;name, col_name) != 0) )
          i++;
  
      if (i &lt; m_table.num_cols)
          return i;
      else
          return -1;
  }
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>ColumnType Table::getColType(const std::string&amp; name_in) const
  {
      const char* name = name_in.c_str();
      int id = getColumnId(name) ;
      return getColType(id) ;
  }
  
  and 
  
  int Table::getColumnId (const std::string&amp; col_name_in) const
  {
      const char* col_name = col_name_in.c_str();
      unsigned int i = 0;
  
      while ((i &lt; m_table.num_cols) &amp;&amp; (strcmp(m_table.cols[i]-&gt;name, col_name) != 0) )
          i++;
  
      if (i &lt; m_table.num_cols)
          return i;
      else
          return -1;
  }
  </code></pre>
  
  <p>In the new code, I am passing a const char* to functions that are now expecting a reference to const std::string. I know std::string can be initialised from a const char*, and the code compiles correctly (no warnings etc).</p>
  
  <p>But I just want to make sure that I am not doing anything that will come to bite me later on (I18n issues aside).</p>
  
  <p>In short - is what am doing "safe"?</p>