<?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[Rundungsproblem beim Schreiben in File]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich schreibe gerade ein Programm, dass ich für die Auswertung einer Messung brauche. Im Grunde macht das Programm folgende Dinge 1. Dateien einlesen 2. Verändern 3. abspeichern - beim abspeichern habe ich ein problem, da er meinen ersten Messwert rundet (der ist 13 Stellig und ich kriege immer ein e rein - was leider nicht das Ziel ist). Kann mir jemand helfen - der betreffenede Codeabschnitt ist unten angeführt!</p>
<p>Danke!</p>
<pre><code>std::ofstream outfile;                // Output-Datei intiallisieren
	std::stringstream out_data;
	out_data&lt;&lt;filename.str()&lt;&lt;&quot;all.txt&quot;; // File zum Speichern
	outfile.open (out_data.str(), ios_base::app);	
	int h=0;

	// Alles in eine Datei! 
	for (int i=0; i&lt;(channel_max+1); i++)
		{	std::ifstream infile;       // Input-Datei initialisieren
			std::stringstream raw_data;
			if (i&lt;10)
				{raw_data.str(&quot;&quot;);
				raw_data&lt;&lt;filename.str()&lt;&lt;&quot;0&quot;&lt;&lt;i&lt;&lt;&quot;.list&quot;;} //Filename zum Laden
			else
				{raw_data.str(&quot;&quot;);
				raw_data&lt;&lt;filename.str()&lt;&lt;i&lt;&lt;&quot;.list&quot;;}
			std::cout &lt;&lt;raw_data.str() &lt;&lt; &quot;\n&quot; ;
			infile.open (raw_data.str());
			h=i;
			while (check&lt;1)
			{	double a=0,b,c; 
				infile&gt;&gt;a&gt;&gt;b&gt;&gt;c;
				/*if (i/8&lt;1)
					timestemp=a;
				if (i/8&lt;2 &amp;&amp; i/8&gt;0.99)
					timestemp=a+t_offset12;
				if (i/8&lt;3 &amp;&amp; i/8&gt;1.99)
					timestemp=a+t_offset13;
				if (i/8&lt;4 &amp;&amp; i/8&gt;2.99)
					timestemp=a+t_offset14;
				if (i/8&lt;5 &amp;&amp; i/8&gt;3.99)
					timestemp=a+t_offset15;
				if (i/8&lt;6 &amp;&amp; i/8&gt;4.99)
					timestemp=a+t_offset12; */
				if (h&lt;1.5)
					{timestemp=a;}
				if (h&lt;2.5 &amp;&amp; h&gt;1.5)
				{timestemp=a+t_offset12;}
				 if (h&lt;3.5 &amp;&amp; h&gt;2.5)
				{timestemp=a+t_offset13;}
				if (h&lt;4.5 &amp;&amp; h&gt;3.5)
				{timestemp=a+t_offset14;}
				if (h&lt;5.5 &amp;&amp; h&gt;4.5)
				{timestemp=a+t_offset15;}
				if (h&lt;6.5 &amp;&amp; h&gt;5.5)
					{timestemp=a+t_offset16;}
				if (a&gt;0)
				{outfile &lt;&lt; timestemp &lt;&lt; &quot;\t&quot; &lt;&lt; b &lt;&lt;&quot;\t&quot;&lt;&lt; c &lt;&lt; &quot;\t&quot; &lt;&lt; i &lt;&lt; &quot;\n&quot; ;} // Schreiben der Outputdatei Reihenfolge [ t sg lg # ]
				else
					{check=1;} 
			}
			infile.close();
			check=0;
	}
	outfile.close();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/314080/rundungsproblem-beim-schreiben-in-file</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 20:57:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/314080.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Feb 2013 07:36:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 07:36:09 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich schreibe gerade ein Programm, dass ich für die Auswertung einer Messung brauche. Im Grunde macht das Programm folgende Dinge 1. Dateien einlesen 2. Verändern 3. abspeichern - beim abspeichern habe ich ein problem, da er meinen ersten Messwert rundet (der ist 13 Stellig und ich kriege immer ein e rein - was leider nicht das Ziel ist). Kann mir jemand helfen - der betreffenede Codeabschnitt ist unten angeführt!</p>
<p>Danke!</p>
<pre><code>std::ofstream outfile;                // Output-Datei intiallisieren
	std::stringstream out_data;
	out_data&lt;&lt;filename.str()&lt;&lt;&quot;all.txt&quot;; // File zum Speichern
	outfile.open (out_data.str(), ios_base::app);	
	int h=0;

	// Alles in eine Datei! 
	for (int i=0; i&lt;(channel_max+1); i++)
		{	std::ifstream infile;       // Input-Datei initialisieren
			std::stringstream raw_data;
			if (i&lt;10)
				{raw_data.str(&quot;&quot;);
				raw_data&lt;&lt;filename.str()&lt;&lt;&quot;0&quot;&lt;&lt;i&lt;&lt;&quot;.list&quot;;} //Filename zum Laden
			else
				{raw_data.str(&quot;&quot;);
				raw_data&lt;&lt;filename.str()&lt;&lt;i&lt;&lt;&quot;.list&quot;;}
			std::cout &lt;&lt;raw_data.str() &lt;&lt; &quot;\n&quot; ;
			infile.open (raw_data.str());
			h=i;
			while (check&lt;1)
			{	double a=0,b,c; 
				infile&gt;&gt;a&gt;&gt;b&gt;&gt;c;
				/*if (i/8&lt;1)
					timestemp=a;
				if (i/8&lt;2 &amp;&amp; i/8&gt;0.99)
					timestemp=a+t_offset12;
				if (i/8&lt;3 &amp;&amp; i/8&gt;1.99)
					timestemp=a+t_offset13;
				if (i/8&lt;4 &amp;&amp; i/8&gt;2.99)
					timestemp=a+t_offset14;
				if (i/8&lt;5 &amp;&amp; i/8&gt;3.99)
					timestemp=a+t_offset15;
				if (i/8&lt;6 &amp;&amp; i/8&gt;4.99)
					timestemp=a+t_offset12; */
				if (h&lt;1.5)
					{timestemp=a;}
				if (h&lt;2.5 &amp;&amp; h&gt;1.5)
				{timestemp=a+t_offset12;}
				 if (h&lt;3.5 &amp;&amp; h&gt;2.5)
				{timestemp=a+t_offset13;}
				if (h&lt;4.5 &amp;&amp; h&gt;3.5)
				{timestemp=a+t_offset14;}
				if (h&lt;5.5 &amp;&amp; h&gt;4.5)
				{timestemp=a+t_offset15;}
				if (h&lt;6.5 &amp;&amp; h&gt;5.5)
					{timestemp=a+t_offset16;}
				if (a&gt;0)
				{outfile &lt;&lt; timestemp &lt;&lt; &quot;\t&quot; &lt;&lt; b &lt;&lt;&quot;\t&quot;&lt;&lt; c &lt;&lt; &quot;\t&quot; &lt;&lt; i &lt;&lt; &quot;\n&quot; ;} // Schreiben der Outputdatei Reihenfolge [ t sg lg # ]
				else
					{check=1;} 
			}
			infile.close();
			check=0;
	}
	outfile.close();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2300153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300153</guid><dc:creator><![CDATA[Lummel202]]></dc:creator><pubDate>Wed, 20 Feb 2013 07:36:09 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 08:10:56 GMT]]></title><description><![CDATA[<p>Hallo Lummel202,</p>
<p>Willkommen im C++-Forum.</p>
<p>Was Dir fehlt ist das Wissen über Manipulatoren für den Ausgabestream. Schau Dir mal <a href="http://www.cplusplus.com/reference/iomanip/setprecision" rel="nofollow">setprecision</a>, <a href="http://www.cplusplus.com/reference/iomanip/setw" rel="nofollow">setw</a> und <a href="http://www.cplusplus.com/reference/iomanip/setfill" rel="nofollow">setfill</a> an.<br />
'<a href="http://dict.leo.org/ende?lp=ende&amp;lang=de&amp;searchLoc=0&amp;cmpType=relaxed&amp;sectHdr=on&amp;spellToler=&amp;search=timestamp" rel="nofollow">timestamp</a>' mit 'a'.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300159</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 20 Feb 2013 08:10:56 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 08:41:17 GMT]]></title><description><![CDATA[<p>Moin Lummel.<br />
Mit den Manipulatoren kannst Du auch dieses <code>stringstream</code> -Geraffel am Anfang vereinfachen.<br />
Ausserdem hilft Dir <code>if-else-if</code> beim formulieren des Hauptteils, der logisch auch nicht ganz schluessig, da bei Dir Lücken in den Bereichen sind - z.B. h == 3.5...<br />
Ungetestet, aber der Grundgedanke kommt rüber:</p>
<pre><code class="language-cpp">std::ofstream outfile(filename + &quot;all.txt&quot;, std::ios_base::app);
  // Alles in eine Datei!
  for (int i=0; i&lt;(channel_max+1); i++)
    {
      std::stringstream raw_data(filename);
      raw_data &lt;&lt; std::setfill('0') &lt;&lt; std::setw(2) &lt;&lt; i &lt;&lt; &quot;.list&quot;;
      std::cout &lt;&lt; raw_data.str() &lt;&lt; '\n';
      std::ifstream infile(raw_data.str());
      h=i;
      while (true)
        {
          double a,b,c;
          infile&gt;&gt;a&gt;&gt;b&gt;&gt;c;
          if (h &lt; 1.5)
            timestamp = a;
          else if(h &lt; 2.5)
            timestamp = a + offset12;
          else if(h &lt; 3.5)
            timestamp = a + offset13;
          else if(h &lt; 4.5)
            timestamp = a + offset14;
          else if(h &lt; 5.5)
            timestamp = a + offset15;
          else if(h &lt; 6.5)
            timestamp = a + offset16;
          if(0&lt;a)
            outfile &lt;&lt; timestamp &lt;&lt; '\t' &lt;&lt; b &lt;&lt; '\t'&lt;&lt; c &lt;&lt; '\t' &lt;&lt; i &lt;&lt; '\n' ;
          else
            break;
        }
    }
</code></pre>
<p>Gott zum Gruße!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300167</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300167</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 20 Feb 2013 08:41:17 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 09:14:03 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>vielen Dank schoneinmal für das Antworten - allerdings verändere ich doch jetzt nur den filename meines Inputfiles - normalerweiße muss ich doch das outputfile verändern oder verstehe ich das falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300183</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300183</guid><dc:creator><![CDATA[Lummel202]]></dc:creator><pubDate>Wed, 20 Feb 2013 09:14:03 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 09:26:36 GMT]]></title><description><![CDATA[<p>Lummel202 schrieb:</p>
<blockquote>
<p>Hey,</p>
<p>vielen Dank schoneinmal für das Antworten - allerdings verändere ich doch jetzt nur den filename meines Inputfiles - normalerweiße muss ich doch das outputfile verändern oder verstehe ich das falsch?</p>
</blockquote>
<p>.. das verstehst Du richtig.<br />
Nur ist es für uns nicht ganz offensichtlich wo das stattfindet. Ich vermute in Zeile 48:</p>
<pre><code>{outfile &lt;&lt; timestemp &lt;&lt; &quot;\t&quot; &lt;&lt; b &lt;&lt;&quot;\t&quot;&lt;&lt; c &lt;&lt; &quot;\t&quot; &lt;&lt; i &lt;&lt; &quot;\n&quot; ;} // Schreiben der Outputdatei Reihenfolge [ t sg lg # ]
</code></pre>
<p>da passt der Kommentar aber nicht zum Inhalt. Geschrieben wird 'timestemp b c i' Kommentar: 't sg lg #' ??</p>
<p>Es reicht wahrscheinlich hinter Zeile 4 ein</p>
<pre><code>outFile &lt;&lt; setpresision(13); // Fliesskommaausgabe mit 13 Dezimalstellen
</code></pre>
<p>hinzuzufügen. Erfordert ein #include &lt;iomanip&gt;.</p>
<p>Falls Du kein Scientific-Format sondern nur festes Format habe willst, so füge noch ein:</p>
<pre><code>outFile &lt;&lt; fixed;
</code></pre>
<p>- dann sind es aber 13 Nachkommastellen (s. <a href="http://www.cplusplus.com/reference/ios/fixed" rel="nofollow">fixed</a>).</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300189</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 20 Feb 2013 09:26:36 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 10:16:16 GMT]]></title><description><![CDATA[<p>Ahh Sorry, hatte das einbinden des outfiles nicht mitkopiert, das steht direkt darüber:</p>
<pre><code>std::ofstream outfile;                // Output-Datei intiallisieren
	std::stringstream out_data;
	out_data&lt;&lt;filename.str()&lt;&lt;&quot;all.list&quot;; // File zum Speichern
	outfile.open (out_data.str(), ios_base::app);	
	int h=0;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2300222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300222</guid><dc:creator><![CDATA[Lummel202]]></dc:creator><pubDate>Wed, 20 Feb 2013 10:16:16 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 10:26:53 GMT]]></title><description><![CDATA[<p>Lummel202 schrieb:</p>
<blockquote>
<pre><code>std::ofstream outfile;                // Output-Datei intiallisieren
	std::stringstream out_data;
	out_data&lt;&lt;filename.str()&lt;&lt;&quot;all.list&quot;; // File zum Speichern
	outfile.open (out_data.str(), ios_base::app);	
	int h=0;
</code></pre>
</blockquote>
<p>Die Zeilen habe ich mir erlaubt in eine zusammenzufassen.<br />
Siehe erste Zeile im Code oben. Die wahrscheinlich richtig so aussehen müsste (ist <code>filename</code> auch ein <code>stringstream</code> ?):</p>
<pre><code class="language-cpp">std::ofstream outfile(filename.str() + &quot;all.txt&quot;, std::ios_base::app);
</code></pre>
<p>Beachte bitte, dass ich weitestgehend nur eine Umformung Deines Codes vorgenommen habe - also strengenommen &quot;Off-topic&quot; bin.<br />
Werners Beiträge hingegen befassen sich mit Deinem Problem mit der Formatierung/Rundung.</p>
<p>Sorry, wenn das mehr verwirrt als hilft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300229</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 20 Feb 2013 10:26:53 GMT</pubDate></item><item><title><![CDATA[Reply to Rundungsproblem beim Schreiben in File on Wed, 20 Feb 2013 21:10:17 GMT]]></title><description><![CDATA[<p>Vielen Dank an alle es hat geklappt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2300482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2300482</guid><dc:creator><![CDATA[Lummel202]]></dc:creator><pubDate>Wed, 20 Feb 2013 21:10:17 GMT</pubDate></item></channel></rss>