title: Getting different output with printf and cout - C++
body: <p>I have a string I am trying to print. when I used <code>cout</code>, it outputs perfectly but using <code>printf</code> leaves it mangled.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>int main ( int argc, char *argv[] )
  {
      // Check to make sure there is a single argument
      if ( argc != 2 )
      {
          cout&lt;&lt;"usage: "&lt;&lt; argv[0] &lt;&lt;" &lt;filename&gt;\n";
          return 1;
      }
  
      // Grab the filename and remove the extension
      std::string filename(argv[1]);
      int lastindex = filename.find_last_of("."); 
      std::string rawname = filename.substr(0, lastindex);
  
      cout &lt;&lt; "rawname:" &lt;&lt; rawname &lt;&lt; endl;
      printf("rawname: %s", rawname);
  
  }
  </code></pre>
  
  <p>The <code>cout</code> gives me "rawname: file"<br>
  The <code>printf</code> gives me "rawname: " and then a bunch of squiggly characters</p>