<?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[C++ fstream will Datei nicht öffnen]]></title><description><![CDATA[<pre><code>// read a file into memory
#include &lt;iostream&gt;     // std::cout
#include &lt;fstream&gt;      // std::ifstream

int main () {

  std::ifstream is (&quot;test.txt&quot;, std::ifstream::binary);
  if (is) {
    // get length of file:
    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);

    char * buffer = new char [length];

    std::cout &lt;&lt; &quot;Reading &quot; &lt;&lt; length &lt;&lt; &quot; characters... &quot;;
    // read data as a block:
    is.read (buffer,length);

    if (is)
      std::cout &lt;&lt; &quot;all characters read successfully.&quot;;
    else
      std::cout &lt;&lt; &quot;error: only &quot; &lt;&lt; is.gcount() &lt;&lt; &quot; could be read&quot;;
    is.close();

    // ...buffer contains the entire file...
	std::cout &lt;&lt; buffer;
	system(&quot;PAUSE&quot;);
    delete[] buffer;
  }
  return 0;
}
</code></pre>
<p>Ist der letzte Codesnippet den ich probiert hab, hab aber auch noch zich andere Sachen probiert die auch alle nicht funktionieren. Das Programm schließt sich sofort da er die txt Datei nicht öffnen kann, habs mit relativem und absolutem Pfad probiert, beides geht nicht.</p>
<p>Hier noch ein anderer Test</p>
<pre><code>char pfad[256]; //hier wird der Programmpfad gespeichert

	_getcwd( pfad, 256); 
	std::string truepfad;
	truepfad = pfad;
	truepfad.append(&quot;\\test.txt&quot;);
	fstream f(&quot;C:\\Users\\Etix\\Documents\\test.txt&quot;); 
    string s;
	if (!f) 
   std::cout &lt;&lt; truepfad;
	else
	{
		std::cout &lt;&lt; &quot;open file&quot;;
		while (getline(f, s)){
			std::cout &lt;&lt; s;
		}
	}
</code></pre>
<p>Mit dem ausgelesenen Pfad der 100% richtig sein muss gehts auch nicht, bin grad echt ratlos <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327962/c-fstream-will-datei-nicht-öffnen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 16:09:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327962.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 13 Sep 2014 13:32:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Sat, 13 Sep 2014 13:32:31 GMT]]></title><description><![CDATA[<pre><code>// read a file into memory
#include &lt;iostream&gt;     // std::cout
#include &lt;fstream&gt;      // std::ifstream

int main () {

  std::ifstream is (&quot;test.txt&quot;, std::ifstream::binary);
  if (is) {
    // get length of file:
    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);

    char * buffer = new char [length];

    std::cout &lt;&lt; &quot;Reading &quot; &lt;&lt; length &lt;&lt; &quot; characters... &quot;;
    // read data as a block:
    is.read (buffer,length);

    if (is)
      std::cout &lt;&lt; &quot;all characters read successfully.&quot;;
    else
      std::cout &lt;&lt; &quot;error: only &quot; &lt;&lt; is.gcount() &lt;&lt; &quot; could be read&quot;;
    is.close();

    // ...buffer contains the entire file...
	std::cout &lt;&lt; buffer;
	system(&quot;PAUSE&quot;);
    delete[] buffer;
  }
  return 0;
}
</code></pre>
<p>Ist der letzte Codesnippet den ich probiert hab, hab aber auch noch zich andere Sachen probiert die auch alle nicht funktionieren. Das Programm schließt sich sofort da er die txt Datei nicht öffnen kann, habs mit relativem und absolutem Pfad probiert, beides geht nicht.</p>
<p>Hier noch ein anderer Test</p>
<pre><code>char pfad[256]; //hier wird der Programmpfad gespeichert

	_getcwd( pfad, 256); 
	std::string truepfad;
	truepfad = pfad;
	truepfad.append(&quot;\\test.txt&quot;);
	fstream f(&quot;C:\\Users\\Etix\\Documents\\test.txt&quot;); 
    string s;
	if (!f) 
   std::cout &lt;&lt; truepfad;
	else
	{
		std::cout &lt;&lt; &quot;open file&quot;;
		while (getline(f, s)){
			std::cout &lt;&lt; s;
		}
	}
</code></pre>
<p>Mit dem ausgelesenen Pfad der 100% richtig sein muss gehts auch nicht, bin grad echt ratlos <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417383</guid><dc:creator><![CDATA[Etix]]></dc:creator><pubDate>Sat, 13 Sep 2014 13:32:31 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Sat, 13 Sep 2014 13:44:58 GMT]]></title><description><![CDATA[<p>Also bei mir gehts unter Win8 mit dem Cygwin GCC 4.8.1.<br />
Hast du vielleicht die Datei schreibgeschützt oder sowas? Vielleicht was mit Adminrechten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417386</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 13 Sep 2014 13:44:58 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Mon, 15 Sep 2014 20:41:03 GMT]]></title><description><![CDATA[<p>Wenn du Flags mit angibst, werden die default-Flags im Konstruktor überschrieben. Du musst also auch ios::in oder ios::out mit angeben. Die Reihenfolge ist dabei ebenfalls wichtig, habe ich aber grad nicht im Kopf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417671</guid><dc:creator><![CDATA[Gastpost]]></dc:creator><pubDate>Mon, 15 Sep 2014 20:41:03 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Mon, 15 Sep 2014 20:49:52 GMT]]></title><description><![CDATA[<p>Gastpost schrieb:</p>
<blockquote>
<p>Wenn du Flags mit angibst, werden die default-Flags im Konstruktor überschrieben. Du musst also auch ios::in oder ios::out mit angeben. Die Reihenfolge ist dabei ebenfalls wichtig, habe ich aber grad nicht im Kopf.</p>
</blockquote>
<p>Das ist kompletter Stuss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417672</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 15 Sep 2014 20:49:52 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Tue, 16 Sep 2014 04:28:47 GMT]]></title><description><![CDATA[<p>Naja, hat bei mir zumindest mal so ein ähnliches Problem gelöst:</p>
<p>Zitat aus <a href="http://www.cplusplus.com/doc/tutorial/files/" rel="nofollow">http://www.cplusplus.com/doc/tutorial/files/</a>:</p>
<blockquote>
<p>For fstream, the default value is only applied if the function is called without specifying any value for the mode parameter. If the function is called with any value in that parameter the default mode is overridden, not combined.</p>
<p>File streams opened in binary mode perform input and output operations independently of any format considerations. Non-binary files are known as text files, and some translations may occur due to formatting of some special characters (like newline and carriage return characters).</p>
<p>Since the first task that is performed on a file stream is generally to open a file, these three classes include a constructor that automatically calls the open member function and has the exact same parameters as this member.</p>
</blockquote>
<p>Aber ich lasse mich gerne eines besseren belehren, falls ich Begriffe durcheinander geworfen habe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417701</guid><dc:creator><![CDATA[Gastpost]]></dc:creator><pubDate>Tue, 16 Sep 2014 04:28:47 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Tue, 16 Sep 2014 05:08:21 GMT]]></title><description><![CDATA[<p>fstream != ifstream. Außerdem möchte ich doch gerne mal wissen, seit wann bitweises ODER nicht mehr assoziativ sein soll. Du hast wahrscheinlich irgendwas anderes bei dir falsch gemacht, hast wild rumprobiert, irgendwann funktionierte es zufällig und nun glaubst du irgendwas daraus gelernt zu haben, dabei war es einfach nur Zufall.</p>
<p>PS: In deinem Link, bloß ein bisschen weiter gelesen, wird es richtig erklärt:</p>
<blockquote>
<p>For ifstream and ofstream classes, ios::in and ios::out are automatically and respectively assumed, even if a mode that does not include them is passed as second argument to the open member function (the flags are combined).</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2417702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417702</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 16 Sep 2014 05:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Tue, 16 Sep 2014 04:59:55 GMT]]></title><description><![CDATA[<p>Würde mich wundern, wenn<br />
out|binary<br />
was anderes ergäbe als<br />
binary|out</p>
<p>Dann müßte ich den operator| wegwerfen und mir einen neuen kaufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417703</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 16 Sep 2014 04:59:55 GMT</pubDate></item><item><title><![CDATA[Reply to C++ fstream will Datei nicht öffnen on Tue, 16 Sep 2014 05:02:12 GMT]]></title><description><![CDATA[<p>Gastpost schrieb:</p>
<blockquote>
<p>Wenn du Flags mit angibst, werden die default-Flags im Konstruktor überschrieben. Du musst also auch ios::in oder ios::out mit angeben.</p>
</blockquote>
<p>Mach ich nie bei ifstream und ofstream und es klappt trotzdem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2417704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2417704</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 16 Sep 2014 05:02:12 GMT</pubDate></item></channel></rss>