<?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[aus datei lesen&#x2F; von string nach double]]></title><description><![CDATA[<p>hallo, als anfänger stehe ich zur zeit vor einem kleinen problem.<br />
ich möchte auf eine Datei zugreifen, in der ein Datum in der folgenden form steht: &quot;JJJJ-MM-TT&quot;. Ich möchte nun dieses Datum in eine Variable des Typs time_t einlesen , also jeweils eine für Jahr, Monat und Tag( eine weitere funktion übernimmt dass dann, und verarbeitet es weiter).</p>
<p>Nur weiß ich im Moment nicht, wie man etwas aus einer datei einlesen kann und dann von char oder string in double, time_t oder so konvertieren kann. Kann mir jemand ein ein kleines codebeispiel für mein problem liefern??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/225750/aus-datei-lesen-von-string-nach-double</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 00:56:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/225750.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Oct 2008 12:50:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to aus datei lesen&#x2F; von string nach double on Fri, 24 Oct 2008 12:50:39 GMT]]></title><description><![CDATA[<p>hallo, als anfänger stehe ich zur zeit vor einem kleinen problem.<br />
ich möchte auf eine Datei zugreifen, in der ein Datum in der folgenden form steht: &quot;JJJJ-MM-TT&quot;. Ich möchte nun dieses Datum in eine Variable des Typs time_t einlesen , also jeweils eine für Jahr, Monat und Tag( eine weitere funktion übernimmt dass dann, und verarbeitet es weiter).</p>
<p>Nur weiß ich im Moment nicht, wie man etwas aus einer datei einlesen kann und dann von char oder string in double, time_t oder so konvertieren kann. Kann mir jemand ein ein kleines codebeispiel für mein problem liefern??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604175</guid><dc:creator><![CDATA[yakult]]></dc:creator><pubDate>Fri, 24 Oct 2008 12:50:39 GMT</pubDate></item><item><title><![CDATA[Reply to aus datei lesen&#x2F; von string nach double on Fri, 24 Oct 2008 13:06:50 GMT]]></title><description><![CDATA[<p>Erkundige dich mal über <code>std::fstream</code> und <code>std::stringstream</code> .</p>
<p><a href="http://www.cplusplus.com/reference" rel="nofollow">Das</a> ist eine empfehlenswerte Referenz dazu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604186</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 24 Oct 2008 13:06:50 GMT</pubDate></item><item><title><![CDATA[Reply to aus datei lesen&#x2F; von string nach double on Fri, 24 Oct 2008 13:09:53 GMT]]></title><description><![CDATA[<p>Da gibt es verschieden Möglichkeiten. Entweder du schreibst dir eine Funktion, die dir das Laden übernimmt, oder du kannst auch &quot;gemütlich&quot; eine Datumsklasse schreiben, die dir das ganze wrappt und die du auch einfach ausgeben/einlesen kannst. ( Habe glaube mal eine hier im Forum gesehen. Ist noch eine rechte Arbeit..).</p>
<p>Die einfachere Möglichkeit ist, wie gesagt eine Funktion zu schreiben, die dir das ganze übernimmt.<br />
Das hier liest dir ein Datum aus einer Datei ein. Das kannst du mal studieren und dann für dich selbst umsetzen.</p>
<pre><code class="language-cpp">std::ifstream in (&quot;dates.txt&quot;);
int year = 0;	
int month = 0;
int day = 0;

char dump;
in &gt;&gt; year &gt;&gt; dump &gt;&gt; month &gt;&gt; dump &gt;&gt; day;

std::cout &lt;&lt; year &lt;&lt; &quot;-&quot; &lt;&lt; month &lt;&lt; &quot;-&quot; &lt;&lt; day;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1604188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604188</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 24 Oct 2008 13:09:53 GMT</pubDate></item><item><title><![CDATA[Reply to aus datei lesen&#x2F; von string nach double on Fri, 24 Oct 2008 13:10:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">ifstream infile(dateiname);
int year;
int month;
int day;

infile&gt;&gt;year;
infile.ignore(1);
infile&gt;&gt;month;
infile.ignore(1);
infile&gt;&gt;day;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1604189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604189</guid><dc:creator><![CDATA[vlad_tepesch]]></dc:creator><pubDate>Fri, 24 Oct 2008 13:10:12 GMT</pubDate></item><item><title><![CDATA[Reply to aus datei lesen&#x2F; von string nach double on Fri, 24 Oct 2008 16:32:59 GMT]]></title><description><![CDATA[<p>Der Standard sieht dafür die <a href="http://www2.roguewave.com/support/docs/leif/sourcepro/html/stdlibref/time-get.html" rel="nofollow">Facette time_get</a> vor.<br />
Das ist aber ziemlich aufwändig, da das Format nicht üblich ist, müsstest Du Dir eine eigene abgeleitete Facette schreiben.</p>
<p>Einfacher geht's mit einer eigenen kleinen Funktion, wie schon von Drakon angedeutet.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;ctime&gt;

// --   liest ein Datum im Format JJJJ-MM-TT 
std::istream&amp; operator&gt;&gt;( std::istream&amp; in, std::tm&amp; time_ )
{
    const std::ios_base::fmtflags flgs = in.flags();
    char m1, m2;
    if( in &gt;&gt; time_.tm_year &gt;&gt; std::noskipws &gt;&gt; m1 &gt;&gt; time_.tm_mon &gt;&gt; m2 &gt;&gt; time_.tm_mday 
            &amp;&amp; (m1 != '-' || m2 != '-') )
        in.setstate( std::ios_base::failbit );
    in.flags( flgs );
    return in;
}

int main()
{
    using namespace std;
    std::tm datum;
    ifstream in(&quot;datei.txt&quot;);
    if( in &gt;&gt; datum )
    {
        cout &lt;&lt; &quot;Datum gelesen &quot; &lt;&lt; endl;
    }
    return 0;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604305</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Fri, 24 Oct 2008 16:32:59 GMT</pubDate></item></channel></rss>