C++ http://blog.samat.org/taxonomy/term/7/0 en Today's g++/C++ funny: ofstream's open constructor http://blog.samat.org/2005/07/07/todays_cpp_funny_ofstreams_open_constructor <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>So, I&#8217;m working on a project, and have some code like&nbsp;this:</p> <p><code type="cpp"> string blah="somefile"; ofstream&nbsp;fp;</p> <p>fp.open(blah); </code></p> <p>And it doesn&#8217;t work. Apparently, what you need to do when using ofstream&#8217;s open&nbsp;method:</p> <p><code type="cpp"> fp.open(blah.c_str()); </code></p> <p>Yes, it looks like what it is. Apparently g++&#8217;s iostreams library (gcc 3.2) does not support things that have been part of the C++ standard for years&#8211;like C++ <span class="caps">STL</span> strings&#8230; You have to convert back to a C&nbsp;string.</p> <p>Last I checked this was 2005, not 1999. You&#8217;d have thought someone would have overloaded this by now&#8230; I&#8217;ve only checked this in g++; will check with Intel&#8217;s C++ compiler and Microsoft Visual Studio later, though I&#8217;m not sure whether to expect better. What didn&#8217;t help me to find this out, of course, is g++&#8217;s totally wonderful (sarcasm) compiler error&nbsp;messages&#8230;</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Topic:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/tag/Programming" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Programming</a></div><div class="field-item odd"><a href="/tag/C" typeof="skos:Concept" property="rdfs:label skos:prefLabel">C</a></div><div class="field-item even"><a href="/tag/Cpp" typeof="skos:Concept" property="rdfs:label skos:prefLabel">C++</a></div></div></div> Thu, 07 Jul 2005 22:43:00 +0000 Samat Jain 41 at http://blog.samat.org