<?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++] Ausgabe in Textdatei: Spaltenweise schreiben]]></title><description><![CDATA[<p>Hallo Leute!</p>
<p>ich habe folgendes Problem und irgendwie ein Brett vorm Kopf. Eigentlich sollte das nicht so schwer lösbar sein. Ich möchte in folgendem Quelltext die sich ändernden Objektvalues Phenotyp(0) und Phenotyp(1) spaltenweise untereinander schreiben. Und zwar so:</p>
<p>P0 p0 p0<br />
P1 p1 p1</p>
<p>da eventuelle noch mehr Phenotypen hinzukommen werden, sollte das ganze in eine schleife gepackt werden.</p>
<pre><code class="language-cpp">std::ofstream outuebergabe(uebergabe, std::ios::out| std::ios::ate);

int j=1; //Ind.-zähler

int y= 2; // liefert ANzahl der Phenotypen zurück, probieren mit genom.nphenotype oder Anz_var benutzen aus VAriablen.dat!!!

// dateierg und uebergabe fuellen mit Ergebnissen der Berechnung der Startpopulation, uebergabe wird dabei bei jeder neuen Generation wieder überschrieben

for(int ii=0; ii&lt;ga.population().size(); ii++){
	genome = ga.population().individual(ii); 										//genome als Objektvar. für individum festlegen, dient zur Abkürzung des Ausdrucks

	outuebergabe &lt;&lt; j &lt;&lt; &quot; x1 &quot; &lt;&lt; genome.phenotype(0) &lt;&lt; &quot;\n &quot; &lt;&lt; j &lt;&lt; &quot; x2 &quot; &lt;&lt; genome.phenotype(1);			

	}
</code></pre>
<p>Wie bekomme ich das hin?</p>
<p>Danke für eure Hilfe.</p>
<p>Grüße</p>
<p>Guddy</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/219150/c-ausgabe-in-textdatei-spaltenweise-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 12:28:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/219150.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Jul 2008 10:29:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 10:29:42 GMT]]></title><description><![CDATA[<p>Hallo Leute!</p>
<p>ich habe folgendes Problem und irgendwie ein Brett vorm Kopf. Eigentlich sollte das nicht so schwer lösbar sein. Ich möchte in folgendem Quelltext die sich ändernden Objektvalues Phenotyp(0) und Phenotyp(1) spaltenweise untereinander schreiben. Und zwar so:</p>
<p>P0 p0 p0<br />
P1 p1 p1</p>
<p>da eventuelle noch mehr Phenotypen hinzukommen werden, sollte das ganze in eine schleife gepackt werden.</p>
<pre><code class="language-cpp">std::ofstream outuebergabe(uebergabe, std::ios::out| std::ios::ate);

int j=1; //Ind.-zähler

int y= 2; // liefert ANzahl der Phenotypen zurück, probieren mit genom.nphenotype oder Anz_var benutzen aus VAriablen.dat!!!

// dateierg und uebergabe fuellen mit Ergebnissen der Berechnung der Startpopulation, uebergabe wird dabei bei jeder neuen Generation wieder überschrieben

for(int ii=0; ii&lt;ga.population().size(); ii++){
	genome = ga.population().individual(ii); 										//genome als Objektvar. für individum festlegen, dient zur Abkürzung des Ausdrucks

	outuebergabe &lt;&lt; j &lt;&lt; &quot; x1 &quot; &lt;&lt; genome.phenotype(0) &lt;&lt; &quot;\n &quot; &lt;&lt; j &lt;&lt; &quot; x2 &quot; &lt;&lt; genome.phenotype(1);			

	}
</code></pre>
<p>Wie bekomme ich das hin?</p>
<p>Danke für eure Hilfe.</p>
<p>Grüße</p>
<p>Guddy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556256</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 10:29:42 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:29:09 GMT]]></title><description><![CDATA[<p>mit</p>
<pre><code class="language-cpp">&quot;\t&quot;
</code></pre>
<p>in einem String kannst du Tabulatoren setzen. Vielleicht reicht dir das schon als &quot;Tabelle&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556314</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:29:09 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:35:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">cout &lt;&lt; width(x) &lt;&lt; text &lt;&lt; width(y) &lt;&lt; text2 &lt;&lt; endl;
</code></pre>
<p>ist wesentlich besser als \t, da dir das schnell was zerhaut, wenn etwas zu lang ist. Und da die Länge eines Tabs nicht immer gleich ist bzw. dargestellt wird, ist es sowieso nicht zu empfehlen.</p>
<p>Du willst also die einzelnen Datensätze nebeneinander darstellen?<br />
Da gibt es verschiedene Optionen.</p>
<p>- du gehst über alle Datensätze und gibst von jedem den ersten Wert aus und wiederholst das komplett für alle Werte<br />
- du gehst über alle Datensätze und speicherst die Ausgabe in einem Buffer für jeden Wert zwischen und gibst es am Ende aus.<br />
- sonstige Methoden</p>
<p>Die zweite ist mE am übersichtlichsten, da du auch nur eine Schleife hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556318</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:35:07 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:36:55 GMT]]></title><description><![CDATA[<p>hatte ich schon probiert:</p>
<pre><code class="language-cpp">outuebergabe &lt;&lt; j &lt;&lt; &quot; x1 &quot; &lt;&lt; genome.phenotype(0) &lt;&lt; &quot;\n &quot; &lt;&lt; j &lt;&lt; &quot; x2 &quot; &lt;&lt; genome.phenotype(1) &lt;&lt; &quot;\t&quot;;
</code></pre>
<p>die ausgabe ist dann:</p>
<p>p0<br />
p1 p0<br />
p1 p0<br />
p1 p0</p>
<p>was mach ich da falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556320</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:36:55 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:39:27 GMT]]></title><description><![CDATA[<p>Das Ergebnis ist doch genau das, was du laut Quelltext haben willst.</p>
<p>Oder hast du \t und \n in der Ausgabe vertauscht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556322</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:39:27 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:50:42 GMT]]></title><description><![CDATA[<p>jedes neue Wertepaar (p0 und p1) soll in eine neue Spalte geschrieben werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556323</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:50:42 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 11:55:54 GMT]]></title><description><![CDATA[<p>Fellhuhn schrieb:</p>
<blockquote>
<p>Das Ergebnis ist doch genau das, was du laut Quelltext haben willst.</p>
<p>Oder hast du \t und \n in der Ausgabe vertauscht?</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1556331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556331</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 11:55:54 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:03:43 GMT]]></title><description><![CDATA[<p>wie gesagt ich bekomme mit dem code das serviert:</p>
<p>p0<br />
p1 p0<br />
p1 p0<br />
p1 p0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556340</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:03:43 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:06:05 GMT]]></title><description><![CDATA[<p>hmm beschreib bitte nochmal genau, wie du die Ausgabe haben willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556342</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556342</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:06:05 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:09:18 GMT]]></title><description><![CDATA[<p>Statt</p>
<pre><code class="language-cpp">outuebergabe &lt;&lt; j &lt;&lt; &quot; x1 &quot; &lt;&lt; genome.phenotype(0) &lt;&lt; &quot;\n &quot; &lt;&lt; j &lt;&lt; &quot; x2 &quot; &lt;&lt; genome.phenotype(1) &lt;&lt; &quot;\t&quot;;
</code></pre>
<p>dann</p>
<pre><code class="language-cpp">outuebergabe &lt;&lt; j &lt;&lt; &quot; x1 &quot; &lt;&lt; genome.phenotype(0) &lt;&lt; &quot;\t &quot; &lt;&lt; j &lt;&lt; &quot; x2 &quot; &lt;&lt; genome.phenotype(1) &lt;&lt; &quot;\n&quot;;
</code></pre>
<p>oder eben:</p>
<pre><code class="language-cpp">for(int idx = 0; idx &lt; 2; ++idx)
{
  outuebergabe &lt;&lt; j &lt;&lt; &quot; x&quot; &lt;&lt; (idx+1) &lt;&lt; &quot; &quot; &lt;&lt; genome.phenotype(idx);
  if (idx != 1)
  {
    outuebergabe &lt;&lt; &quot;\t &quot;;
  }
}
outuebergabe &lt;&lt; &quot;\n&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1556344</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556344</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:09:18 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:16:36 GMT]]></title><description><![CDATA[<p>so wollte ich es eben nicht haben: sondern so:</p>
<p>beim ersten Durchlauf:</p>
<p>p0-1<br />
p1-1</p>
<p>beim zweiten durchlauf:</p>
<p>p0-1 p0-2<br />
p0-1 p0-2</p>
<p>beim dritten:</p>
<p>p0-1 p0-2 p0-3<br />
p0-1 p0-2 p0-3</p>
<p>usw.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556353</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:16:36 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:30:45 GMT]]></title><description><![CDATA[<p>Versteh ich nicht. Ich sehe da keinerlei Zusammenhang zwischen dem was zu schreibst und deinen Variablen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556371</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:30:45 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 12:38:39 GMT]]></title><description><![CDATA[<p>@ fellhuhn: wieso? die Wertepaare sollen jeweils eine eigene Spalte(nicht Zeile) bekommen, die durch einen Tabulator getrennt sind. siehe letzten Beitrag von mir. Bei deinem beispiel wird es eben zeilenweise geschrieben und das möchte ich halt nicht! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556377</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 12:38:39 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 13:14:36 GMT]]></title><description><![CDATA[<p>In deinem Quellcode gibst du offensichtlich für jedes genompaar (nämlich in jedem Schleifendurchlauf) einen Zeilenumbruch aus. Da du aber nur einen einzigen Zeilenumbruch willst ist das offenbar falsch.<br />
In C++ kann man leider nicht ohne weiteres eine spaltenweise Ausgabe machen, da man dazu immer wieder in die vorherige Zeile springen müsste. Das ist aber mit Standard C++ nicht machbar. (Es gibt aber irgendwelche Konsole-Frameworks die das vielleicht können)</p>
<p>Die Lösung für Standard-C++ ist also, dir erst die Zeilen zusammenzubasteln und sie dann auszugeben, wenn du fertig bist. Ich würds in etwa wie folgt anstellen:</p>
<pre><code class="language-cpp">ostringstream zeile0(&quot;Phenotyp 0: &quot;);
ostringstream zeile1(&quot;Phenotyp 1: &quot;);
for(int ii=0, end=ga.population().size(); ii&lt;end; ++ii)
{
  genome = ga.population().individual(ii);
  zeile0 &lt;&lt; width(10) &lt;&lt; genome.phenotype(0);
  zeile1 &lt;&lt; width(10) &lt;&lt; genome.phenotype(1);
}
outuebergabe &lt;&lt; zeile0.str() &lt;&lt; '\n'
             &lt;&lt; zeile1.str() &lt;&lt; '\n'
             &lt;&lt; std::flush;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1556401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556401</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 30 Jul 2008 13:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to [c++] Ausgabe in Textdatei: Spaltenweise schreiben on Wed, 30 Jul 2008 13:32:02 GMT]]></title><description><![CDATA[<p>Danke, das sollte gehen. Ich hab wohl etwas um die Ecke gedacht! <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556415</guid><dc:creator><![CDATA[guddy]]></dc:creator><pubDate>Wed, 30 Jul 2008 13:32:02 GMT</pubDate></item></channel></rss>