<?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[Int Zahlen von a.txt zu b.text kopieren!]]></title><description><![CDATA[<pre><code class="language-cpp">#include &quot;header.h&quot;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;
int main (){

	int x;
	int max=0;

	ifstream inn(&quot;kontak.txt&quot;);

		while (! inn.eof())
{		  
	      inn &gt;&gt; x;
          ofstream to(&quot;leer_kontak.txt&quot;);
          to &lt;&lt; x &lt;&lt; &quot;\n&quot;;

		  if ( x&gt;max)
			max = x;

}

		cout &lt;&lt; &quot;MAX: &quot; &lt;&lt; max;}
</code></pre>
<p>Es wird immer die kopierte Zahl mit der nächsten Zahl überschrieben.</p>
<p>hmm woran liegt's?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/305525/int-zahlen-von-a-txt-zu-b-text-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 19:02:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/305525.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Jul 2012 14:51:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 15:01:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &quot;header.h&quot;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;
int main (){

	int x;
	int max=0;

	ifstream inn(&quot;kontak.txt&quot;);

		while (! inn.eof())
{		  
	      inn &gt;&gt; x;
          ofstream to(&quot;leer_kontak.txt&quot;);
          to &lt;&lt; x &lt;&lt; &quot;\n&quot;;

		  if ( x&gt;max)
			max = x;

}

		cout &lt;&lt; &quot;MAX: &quot; &lt;&lt; max;}
</code></pre>
<p>Es wird immer die kopierte Zahl mit der nächsten Zahl überschrieben.</p>
<p>hmm woran liegt's?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2228905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228905</guid><dc:creator><![CDATA[SinnMeister]]></dc:creator><pubDate>Sun, 01 Jul 2012 15:01:42 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 15:12:16 GMT]]></title><description><![CDATA[<p>Mach den Scope <code>to</code> von mal außerhalb des Schleifenkörpers. Momentan wird die Datei bei jedem Durchlauf geschlossen und wieder geöffnet (und dabei ersetzt).</p>
<p>Du wirst auch feststellen, dass du dann immer noch einen Logikfehler hast: Derzeit prüfst du darauf, ob die letzte Leseaktion am Dateiende scheiterte, versuchst dann einen Wert zu lesen und speicherst ihn dann ab. Denk mal nach, was passiert, wenn du das Dateiende erreichst.</p>
<p>Du willst daher wohl eher</p>
<pre><code class="language-cpp">while (inn &gt;&gt; x)
 to &lt;&lt; x;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2228908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228908</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 01 Jul 2012 15:12:16 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 15:48:51 GMT]]></title><description><![CDATA[<p>hmm...<br />
Also ich hab eine .txt Datei mit Int Zahlen jeweils mit einem Zeilenvorschub oder Space getrennt.</p>
<p>Von diesen Zahlen will ich das Max bestimmen und alle Int Zahlen in eine leere .txt schreiben.</p>
<p>Auslesen und max. bestimmen klappt.<br />
Beim reinkopieren klappt es nicht.</p>
<p>€ So klappt es fast perfekt, nur wird die ERSTE Zahl beim kopieren übersprungen</p>
<pre><code class="language-cpp">while (!inn.eof())
{		  
	      inn &gt;&gt; x;
         if ( x&gt;max)
		  {max = x;}

	ofstream to(&quot;leer_kontak.txt&quot;);
		while (inn &gt;&gt; x)
        { to &lt;&lt; x &lt;&lt; &quot;\n&quot;;
		}}
</code></pre>
<p>Wenn ich das ofstream außerhalb schreibe, passiert nix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2228924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228924</guid><dc:creator><![CDATA[SinnMeister]]></dc:creator><pubDate>Sun, 01 Jul 2012 15:48:51 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 16:27:34 GMT]]></title><description><![CDATA[<p>Es ist schon klar was du machen möchtest.<br />
Aber entweder hast du SeppJ`s Kommentar dazu nicht gelesen oder komplett ignoriert.</p>
<p>Also nochmal durchlesen, darüber nachdenken (es wurde ja schon ein Hinweis gegeben + ein Lösungsvorschlag) und dann deine Fehler korrigieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2228949</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228949</guid><dc:creator><![CDATA[inter2k3]]></dc:creator><pubDate>Sun, 01 Jul 2012 16:27:34 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 16:50:24 GMT]]></title><description><![CDATA[<p>ich hab alles gelesen und mittlerweile vieles ausprobiert, dass einzige was einigermaßen funktionierte, war die lösung die ich angegeben haben.</p>
<p>Hifle wird hier wirklich sehr kleingeschrieben. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2228960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228960</guid><dc:creator><![CDATA[SinnMeister]]></dc:creator><pubDate>Sun, 01 Jul 2012 16:50:24 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Sun, 01 Jul 2012 16:57:24 GMT]]></title><description><![CDATA[<p>Es wurde empfohlen, den scope von <strong>to</strong> ausserhalb der Schleife zu verlegen. Hast du aber nicht gemacht. Bei jedem Durchgang öffnest und schliesst du deine leer_kontakt.txt, und jedesmal überschreibst du den bisherigen Inhalt.</p>
<p>Auch deine condition wurde angesprochen und dir eine mögliche Verbesserung geschrieben - hast du ebenfalls ignoriert.</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

int main () {

    int x;
    int max=0;
    ifstream inn(&quot;kontakt.txt&quot;);
	ofstream to (&quot;leer_kontakt.txt&quot;);

	while (inn &gt;&gt; x) {         
		to &lt;&lt; x &lt;&lt; &quot;\n&quot;;
        if (x &gt; max)
			max = x;
	}
	cout &lt;&lt; &quot;MAX: &quot; &lt;&lt; max;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2228964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2228964</guid><dc:creator><![CDATA[inter2k3]]></dc:creator><pubDate>Sun, 01 Jul 2012 16:57:24 GMT</pubDate></item><item><title><![CDATA[Reply to Int Zahlen von a.txt zu b.text kopieren! on Mon, 02 Jul 2012 07:37:31 GMT]]></title><description><![CDATA[<p>SinnMeister schrieb:</p>
<blockquote>
<p>Also ich hab eine .txt Datei mit Int Zahlen jeweils mit einem Zeilenvorschub oder Space getrennt. Von diesen Zahlen will ich das Max bestimmen und alle Int Zahlen in eine leere .txt schreiben.</p>
</blockquote>
<p>Ein weiterer Weg wäre z.B. auch dieser:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;vector&gt;

int main()
{
	std::ifstream in(&quot;test.txt&quot;);
	std::vector&lt;int&gt; zahlen((std::istream_iterator&lt;int&gt;(in)),std::istream_iterator&lt;int&gt;());

	const int max = *std::max_element(zahlen.begin(),zahlen.end());
	std::cout &lt;&lt; &quot;max element = &quot; &lt;&lt; max;

	std::ofstream out(&quot;test2.txt&quot;);
	std::copy(zahlen.begin(),zahlen.end(),std::ostream_iterator&lt;int&gt;(out,&quot; &quot;));
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2229116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2229116</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 02 Jul 2012 07:37:31 GMT</pubDate></item></channel></rss>