<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ofstream Konstruktor Probleme]]></title><description><![CDATA[<p>Hallo, ich habe ein Problem mit einem einfachen Header:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;

using namespace std;

class Logfile
{
private:
    ofstream file;
public:
    Logfile()
    {
    file(&quot;logfile.txt&quot;);
    }
    Logfile(string filename)
    {
    file(filename);
    }
//usw.
</code></pre>
<p>Die Konstruktoren werden vom Compiler bemängelt:</p>
<blockquote>
<p>logger.h:29: Fehler: keine Übereinstimmung für Aufruf von »(std::ofstream) (const char [12])«</p>
</blockquote>
<p>bzw.</p>
<blockquote>
<p>logger.h:33: Fehler: keine Übereinstimmung für Aufruf von »(std::ofstream) (std::string&amp;)</p>
</blockquote>
<p>Verstehe den Grund nicht ganz. Ich will es ermöglichen, dass entweder ein File mit Standardnamen erzeugt wird, oder der Name im Konstruktor übergeben werden kann. Wieso wird das so nicht akzeptiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/146730/ofstream-konstruktor-probleme</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 18:27:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/146730.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 May 2006 13:11:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ofstream Konstruktor Probleme on Wed, 10 May 2006 13:11:32 GMT]]></title><description><![CDATA[<p>Hallo, ich habe ein Problem mit einem einfachen Header:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;

using namespace std;

class Logfile
{
private:
    ofstream file;
public:
    Logfile()
    {
    file(&quot;logfile.txt&quot;);
    }
    Logfile(string filename)
    {
    file(filename);
    }
//usw.
</code></pre>
<p>Die Konstruktoren werden vom Compiler bemängelt:</p>
<blockquote>
<p>logger.h:29: Fehler: keine Übereinstimmung für Aufruf von »(std::ofstream) (const char [12])«</p>
</blockquote>
<p>bzw.</p>
<blockquote>
<p>logger.h:33: Fehler: keine Übereinstimmung für Aufruf von »(std::ofstream) (std::string&amp;)</p>
</blockquote>
<p>Verstehe den Grund nicht ganz. Ich will es ermöglichen, dass entweder ein File mit Standardnamen erzeugt wird, oder der Name im Konstruktor übergeben werden kann. Wieso wird das so nicht akzeptiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1054845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1054845</guid><dc:creator><![CDATA[DiethelmKL]]></dc:creator><pubDate>Wed, 10 May 2006 13:11:32 GMT</pubDate></item><item><title><![CDATA[Reply to ofstream Konstruktor Probleme on Wed, 10 May 2006 13:22:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;

using namespace std;

class Logfile
{
private:
    ofstream file;
public:
    Logfile() : file(&quot;logfile.txt&quot;)
    {
    }
    Logfile(string filename) : file(filename.c_str()) // Bin net sicher, obs ohne .c_str() nicht auch geht
    {
    }
//usw.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1054854</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1054854</guid><dc:creator><![CDATA[bluecode]]></dc:creator><pubDate>Wed, 10 May 2006 13:22:12 GMT</pubDate></item><item><title><![CDATA[Reply to ofstream Konstruktor Probleme on Wed, 10 May 2006 15:02:51 GMT]]></title><description><![CDATA[<p>und nun noch ein bischen anders</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;

//using namespace std;  //sollte nie in header-Dateien verwendet werden

class Logfile
{
private:
    std::ofstream file;
public:
//    Logfile() : file(&quot;logfile.txt&quot;) {} // wird vom anderen Konstruktor mit erledigt
    Logfile(const std::string&amp; filename = &quot;logfile.txt&quot;) : file(filename.c_str()) {} // Bin net sicher, obs ohne .c_str() nicht auch geht // nein, außerdem Übergabe als const Referenz
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1054925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1054925</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 10 May 2006 15:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to ofstream Konstruktor Probleme on Wed, 10 May 2006 19:37:45 GMT]]></title><description><![CDATA[<p>Danke Jungs!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1055137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1055137</guid><dc:creator><![CDATA[DiethelmML]]></dc:creator><pubDate>Wed, 10 May 2006 19:37:45 GMT</pubDate></item></channel></rss>