<?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[Scientific Notation für String der gespeichert wird]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin gerade dabei die Erstellung einer Analyse Datei in mein Projekt einzubinden. D.h. in meinen Klassen gibt es eine Funktion summary(), die einen String zurückgibt und dieser dann gespeichert wird. Das sieht wie folgt aus:</p>
<pre><code>void AFC::MixtureFraction::summary() const
{
     //- Open file for writing 
    std::fstream file;

    file.open(&quot;analyze&quot;, std::fstream::out);

    file&lt;&lt; Header();

    file&lt;&lt; chemistry_.summary();
    file&lt;&lt; thermo_.summary();
    file&lt;&lt; transport_.summary();
    file&lt;&lt; gasKinetics_.summary();

    file.close();
}
</code></pre>
<p>Soweit funktioniert das auch. Allerdings sind einige Zahlen mit e^45 usw. definiert. In meiner Analyse Datei sieht das dann wie folgt aus:</p>
<pre><code>Reaction 3:  H+O2(+M)=HO2(+M)
   =============================================

      A:  5580000000000.000000
      n:  0.400000
      Ea: 0.000000 cal/mol

     LOW Coeffs (for high pressure)

         A:  840000000000000000.000000 
         n:  -0.800000
         Ea: 0.000000 cal/mol

     TROE Coeffs

        a:  0.500000
        b:  0.000000
        c:  1000000000000000019884624838656.000000
        d:  0.000000

   Reaction 4:  OH+HO2=H2O+O2
   =============================================

      A:  50000000000000.000000
      n:  0.000000
      Ea: 1000.000000 cal/mol

   Reaction 5:  H+HO2=OH+OH
   =============================================

      A:  250000000000000.000000
      n:  0.000000
      Ea: 1900.000000 cal/mol
</code></pre>
<p>Ich möchte in meiner Datei jedoch die wissenschaftliche Notation (scientific). Wenn ich die Zahlen über std::cout&lt;&lt; std::scientific plotte, dann erhalte ich das gewünschte Ergebnis, jedoch weiß ich nicht wie ich ein double in ein scientific string umwandele, da ich in den Funktionen summary() alles in einen String packe und diesen als Rückgabe Parameter habe. Um einen kurzen Einblick zu geben, hier ein kurzer Ausschnitt aus der summary() Funktion:</p>
<pre><code>if(chemData_.TROE(r))
            {
                tmp += &quot;     TROE Coeffs\n\n&quot;;

                const List&lt;scalar&gt;&amp; TROECoeffs = chemData_.TROECoeffs(r);
                tmp += &quot;        a:  &quot; + toStr(TROECoeffs[0]) + &quot;\n&quot;;
                tmp += &quot;        b:  &quot; + toStr(TROECoeffs[1]) + &quot;\n&quot;;
                tmp += &quot;        c:  &quot; + toStr(TROECoeffs[2]) + &quot;\n&quot;;
                tmp += &quot;        d:  &quot; + toStr(TROECoeffs[3]) + &quot;\n&quot;;
            }
</code></pre>
<p>Das Problem (so scheint es mir) ist die Umwandlung von double in das string Format. toStr ist std::to_string.</p>
<p>Hab schon ein paar sachen probiert aber bislang noch keine positiven Resultate gefunden, außer das es wohl an dieser Umwandlung liegt.</p>
<p>Danke fürs durchlesen,<br />
Grüße Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/338396/scientific-notation-für-string-der-gespeichert-wird</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 19:38:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338396.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 12 Jun 2016 21:29:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Scientific Notation für String der gespeichert wird on Sun, 12 Jun 2016 21:29:21 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin gerade dabei die Erstellung einer Analyse Datei in mein Projekt einzubinden. D.h. in meinen Klassen gibt es eine Funktion summary(), die einen String zurückgibt und dieser dann gespeichert wird. Das sieht wie folgt aus:</p>
<pre><code>void AFC::MixtureFraction::summary() const
{
     //- Open file for writing 
    std::fstream file;

    file.open(&quot;analyze&quot;, std::fstream::out);

    file&lt;&lt; Header();

    file&lt;&lt; chemistry_.summary();
    file&lt;&lt; thermo_.summary();
    file&lt;&lt; transport_.summary();
    file&lt;&lt; gasKinetics_.summary();

    file.close();
}
</code></pre>
<p>Soweit funktioniert das auch. Allerdings sind einige Zahlen mit e^45 usw. definiert. In meiner Analyse Datei sieht das dann wie folgt aus:</p>
<pre><code>Reaction 3:  H+O2(+M)=HO2(+M)
   =============================================

      A:  5580000000000.000000
      n:  0.400000
      Ea: 0.000000 cal/mol

     LOW Coeffs (for high pressure)

         A:  840000000000000000.000000 
         n:  -0.800000
         Ea: 0.000000 cal/mol

     TROE Coeffs

        a:  0.500000
        b:  0.000000
        c:  1000000000000000019884624838656.000000
        d:  0.000000

   Reaction 4:  OH+HO2=H2O+O2
   =============================================

      A:  50000000000000.000000
      n:  0.000000
      Ea: 1000.000000 cal/mol

   Reaction 5:  H+HO2=OH+OH
   =============================================

      A:  250000000000000.000000
      n:  0.000000
      Ea: 1900.000000 cal/mol
</code></pre>
<p>Ich möchte in meiner Datei jedoch die wissenschaftliche Notation (scientific). Wenn ich die Zahlen über std::cout&lt;&lt; std::scientific plotte, dann erhalte ich das gewünschte Ergebnis, jedoch weiß ich nicht wie ich ein double in ein scientific string umwandele, da ich in den Funktionen summary() alles in einen String packe und diesen als Rückgabe Parameter habe. Um einen kurzen Einblick zu geben, hier ein kurzer Ausschnitt aus der summary() Funktion:</p>
<pre><code>if(chemData_.TROE(r))
            {
                tmp += &quot;     TROE Coeffs\n\n&quot;;

                const List&lt;scalar&gt;&amp; TROECoeffs = chemData_.TROECoeffs(r);
                tmp += &quot;        a:  &quot; + toStr(TROECoeffs[0]) + &quot;\n&quot;;
                tmp += &quot;        b:  &quot; + toStr(TROECoeffs[1]) + &quot;\n&quot;;
                tmp += &quot;        c:  &quot; + toStr(TROECoeffs[2]) + &quot;\n&quot;;
                tmp += &quot;        d:  &quot; + toStr(TROECoeffs[3]) + &quot;\n&quot;;
            }
</code></pre>
<p>Das Problem (so scheint es mir) ist die Umwandlung von double in das string Format. toStr ist std::to_string.</p>
<p>Hab schon ein paar sachen probiert aber bislang noch keine positiven Resultate gefunden, außer das es wohl an dieser Umwandlung liegt.</p>
<p>Danke fürs durchlesen,<br />
Grüße Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2498618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2498618</guid><dc:creator><![CDATA[Shor-ty]]></dc:creator><pubDate>Sun, 12 Jun 2016 21:29:21 GMT</pubDate></item><item><title><![CDATA[Reply to Scientific Notation für String der gespeichert wird on Sun, 12 Jun 2016 21:59:08 GMT]]></title><description><![CDATA[<p>Wenn ich dich richtig verstanden habe, suchst du <code>std::stringstream</code> . In deinen summary()-Funktionen packst du alles da rein, wie wenn du es mit <code>std::cout</code> machen würdest und gibst schlussendlich mittels <code>std::stringstream::str()</code> einen String zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2498619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2498619</guid><dc:creator><![CDATA[schtringschtream]]></dc:creator><pubDate>Sun, 12 Jun 2016 21:59:08 GMT</pubDate></item><item><title><![CDATA[Reply to Scientific Notation für String der gespeichert wird on Mon, 13 Jun 2016 05:52:34 GMT]]></title><description><![CDATA[<p>Vielleicht wäre es allgemein eine bessere Idee, eine Ausgabefunktion zu schreiben, die einen ostream als Parameter hat und alles wie gewünscht in diesen schreibt, anstatt den Umweg zu gehen, einen String zu erstellen, weiter zu reichen und letztlich doch nur in einen ostream zu schreiben. Als Namen für diese Ausgabefunktion schlage ich <code>operator&lt;&lt;</code> vor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2498624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2498624</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2016 05:52:34 GMT</pubDate></item><item><title><![CDATA[Reply to Scientific Notation für String der gespeichert wird on Mon, 13 Jun 2016 09:15:11 GMT]]></title><description><![CDATA[<p>Hey Sepp,</p>
<p>danke für die Antwort. Das werde ich mir mal anschauen und sicher auch so umsetzen. Wie du schon erwähnt hast, ist das wesentlich besser wie die Sache die ich mach.</p>
<p>Danke für den Denkanstoß!</p>
<p>Grüße Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2498635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2498635</guid><dc:creator><![CDATA[Shor-ty]]></dc:creator><pubDate>Mon, 13 Jun 2016 09:15:11 GMT</pubDate></item><item><title><![CDATA[Reply to Scientific Notation für String der gespeichert wird on Wed, 15 Jun 2016 19:03:16 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich wollte hier nur noch meine Lösung posten. Wie Sepp bereits erwähnte, habe ich die Funktionen (summary()) nun so abgeändert, dass diese einen ostream aufnimmt und ich in diesen alles speichere:</p>
<pre><code>std::filebuf file;
    file.open(&quot;analyze&quot;, std::ios::out);

    //- Ostream that take the information
    std::ostream data(&amp;file);

    //- Set scientific notation and precision to floatfield
    data.setf(std::ios::scientific, std::ios::floatfield);

    //- Header
    data&lt;&lt; Header() &lt;&lt; &quot;\n&quot;;

    //- Build the chemistry summary
    chemistry_.summary(data);

    //- Build the thermodynamic summary
    thermo_.summary(data);

    file.close();
</code></pre>
<p>Funktionier einwandfrei und ich hab meine scientific notation mit flaot Genauigkeit. Wollte die Genauigkeit auf 4 Nachkommastellen begrenzen aber das wollte nicht. Folgendes hab ich versucht:</p>
<pre><code>data.precision(4);
</code></pre>
<p>Die Info hab ich aus dieser Tabelle: <a href="http://www.cplusplus.com/reference/ostream/ostream/?kw=ostream" rel="nofollow">http://www.cplusplus.com/reference/ostream/ostream/?kw=ostream</a> und sollte auf die nächste Zahl angewendet werden. Will nur leider nicht so, aber das ist jetzt auch kein rießiges Problem.</p>
<p>Danke Sepp für den Hinweis mit dem Ostream.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2498969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2498969</guid><dc:creator><![CDATA[Shor-ty]]></dc:creator><pubDate>Wed, 15 Jun 2016 19:03:16 GMT</pubDate></item></channel></rss>