<?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[ifstream Problem]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Problem mit ifstream beim öffnen von Dateien.<br />
Hier ein Auszug aus dem Code:</p>
<pre><code>#include &lt;fstream.h&gt;
#include &lt;iostream.h&gt;

void main(){

	char *file=(&quot;E:\\Hallo.txt&quot;);
	ifstream f(file);
	if(!f)
		cout&lt;&lt;&quot;error&quot;&lt;&lt;endl;
}
</code></pre>
<p>Mein Problem ist nun folgendes, selbst wenn die Datei nicht existiert wird kein Fehler gemldet, sondern ein Leeres File erstellt.<br />
Wie schaffe ich es, daß Error ausgegeben wird, anstatt ein neues File zu erstellen?</p>
<p>Gruß Alex</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/82986/ifstream-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 05:09:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/82986.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Aug 2004 17:30:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ifstream Problem on Mon, 16 Aug 2004 17:30:32 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Problem mit ifstream beim öffnen von Dateien.<br />
Hier ein Auszug aus dem Code:</p>
<pre><code>#include &lt;fstream.h&gt;
#include &lt;iostream.h&gt;

void main(){

	char *file=(&quot;E:\\Hallo.txt&quot;);
	ifstream f(file);
	if(!f)
		cout&lt;&lt;&quot;error&quot;&lt;&lt;endl;
}
</code></pre>
<p>Mein Problem ist nun folgendes, selbst wenn die Datei nicht existiert wird kein Fehler gemldet, sondern ein Leeres File erstellt.<br />
Wie schaffe ich es, daß Error ausgegeben wird, anstatt ein neues File zu erstellen?</p>
<p>Gruß Alex</p>
]]></description><link>https://www.c-plusplus.net/forum/post/583972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/583972</guid><dc:creator><![CDATA[Alex_H]]></dc:creator><pubDate>Mon, 16 Aug 2004 17:30:32 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream Problem on Mon, 16 Aug 2004 19:10:29 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>1. Du hast in die falsche Rubrik gepostet.<br />
Hier kommen eigentlich nur Fragen über MFC oder zum Visual-* hinein.<br />
Hier geht es um Standard C++.</p>
<p>2. Du solltest nicht mehr schreiben: #include &lt;fstream.h&gt; sondern bei Standard C++ Headern das &quot;.h&quot; weglassen. Die erste Methode ist veraltet.<br />
Aber dann liegt alles im Namespace std , du benötigst also noch ein<br />
&quot;using namespace std&quot; nach den includes.</p>
<p>3. Zur eigentlichen Frage:<br />
Wenn du die ersten beiden Antworten beherzigt hast, hat sich jetzt dein Problem damit erledigt,denn in den Standardkonformen Includes ist das Default-Verhalten so, dass keine Datei erstellt wird. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Ansonsten hättest du noch ein &quot;ios::nocreate&quot; benötigt.</p>
<p>Also nochmal im Stück:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt; 
#include &lt;iostream&gt; 

using namespace std;

int main(){ 

    char *file=(&quot;E:\\Hallo.txt&quot;); 
    ifstream f(file); 

    if(!f) 
        cout&lt;&lt;&quot;error&quot;&lt;&lt;endl; 

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/584067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/584067</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 16 Aug 2004 19:10:29 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream Problem on Mon, 16 Aug 2004 19:33:22 GMT]]></title><description><![CDATA[<p>für den Hinweis, es soll nicht mehr vorkommen!<br />
Dein Vorschlag löst mein Problem, wobei ich mich für das ios::nocreate entschieden habe, da ich nicht abschätzen kann, wie sich die neue Headerdatei auf den Rest meines Programmes auswirkt.</p>
<p>Ich wünsche noch einen schönen Abend!!</p>
<p>Gruß Alex</p>
]]></description><link>https://www.c-plusplus.net/forum/post/584102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/584102</guid><dc:creator><![CDATA[Alex_H]]></dc:creator><pubDate>Mon, 16 Aug 2004 19:33:22 GMT</pubDate></item></channel></rss>