title: Difference between a C++ string and a C-string ( .c_str() )
body: <blockquote>
    <p><strong>Possible Duplicates:</strong>
    <a href="https://stackoverflow.com/questions/4096210/why-does-stdstring-not-provide-a-conversion-to-const-char">Why does std::string not provide a conversion to const char*?</a>
    <a href="https://stackoverflow.com/questions/492061/why-doesnt-stdstring-provide-implicit-conversion-to-char">Why doesn&#39;t std::string provide implicit conversion to char*?</a></p>
  </blockquote>
  
  
  
  <pre><code> case 1 :
   void readFile ( const string&amp; inputfile ) {
       ifstream in ( inputfile  );
   }
  
   case 2:
   void readFile ( const string&amp; inputfile ) {
       ifstream in ( inputfile . c_str() );
   }
  </code></pre>
  
  <p>Of course, I know how I can call <code>ifstream</code> with a required parameter, but what is the real difference between a C++ string and a null-terminated sequence of characters (C-string) .c_str() ?** </p>
  
  <p>I think automatic type conversion should be do its job, that is, automatically convert a C++ string to .c_str(). Am I wrong?</p>
  
  <p>Case 1 gives an error, and case 2 works fine. Is it possible to convert case 1 to case 2 over using <code>static_cast&lt;&gt;</code>?</p>