<?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[Time in txt-Datei schreiben]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte die aktuelle Zeit und das Datum in eine Datei schreiben, leider bekomme ich eine Fehlermeldung:</p>
<p>[C++ Fehler] Unit1.cpp(103): E2015 Mehrdeutigkeit zwischen 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator &lt;&lt;(int)' und 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator &lt;&lt;(double)'</p>
<p>Der Code sieht so aus:</p>
<p>TDateTime t = Time();<br />
TDateTime d = Date();</p>
<p>//Messdaten in Textdatei schreiben<br />
ofstream datei;<br />
datei.open(&quot;C:\\Wetterstation\\Daten.txt&quot; , ios_base::app);<br />
datei&lt;&lt;Temperatur&lt;&lt;'\t'&lt;&lt;Luftdruck&lt;&lt;'\t'&lt;&lt;Feuchte&lt;&lt;'\t'&lt;&lt;Windstaerke&lt;&lt;'\t'&lt;&lt;t&lt;&lt;endl;<br />
datei.close();</p>
<p>Wer kann mir weiterhelfen, kann ja eigentlich nur eine Kleinigkeit sein?</p>
<p>mfg ahl</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/89204/time-in-txt-datei-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 17:08:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/89204.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Oct 2004 15:55:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 15:55:14 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte die aktuelle Zeit und das Datum in eine Datei schreiben, leider bekomme ich eine Fehlermeldung:</p>
<p>[C++ Fehler] Unit1.cpp(103): E2015 Mehrdeutigkeit zwischen 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator &lt;&lt;(int)' und 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt; &gt;::operator &lt;&lt;(double)'</p>
<p>Der Code sieht so aus:</p>
<p>TDateTime t = Time();<br />
TDateTime d = Date();</p>
<p>//Messdaten in Textdatei schreiben<br />
ofstream datei;<br />
datei.open(&quot;C:\\Wetterstation\\Daten.txt&quot; , ios_base::app);<br />
datei&lt;&lt;Temperatur&lt;&lt;'\t'&lt;&lt;Luftdruck&lt;&lt;'\t'&lt;&lt;Feuchte&lt;&lt;'\t'&lt;&lt;Windstaerke&lt;&lt;'\t'&lt;&lt;t&lt;&lt;endl;<br />
datei.close();</p>
<p>Wer kann mir weiterhelfen, kann ja eigentlich nur eine Kleinigkeit sein?</p>
<p>mfg ahl</p>
]]></description><link>https://www.c-plusplus.net/forum/post/630859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/630859</guid><dc:creator><![CDATA[ahl]]></dc:creator><pubDate>Sun, 17 Oct 2004 15:55:14 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 19:06:09 GMT]]></title><description><![CDATA[<p>öhm vielleicht nützt dir aus der stdio.h fopen &amp; fread/fwrite was?<br />
(fclose nicht vergessen)</p>
<p>beispiel:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;

FILE *f;
char datei[]=&quot;C:\\Bla.txt&quot;;

f=fopen(datei,&quot;w&quot;); 
                    /* falls nicht existierend,
                     * wird die datei erstellt,
                     * falls doch überschrieben
                     */
char text[]=&quot;blabla&quot;;
fwrite(text); //die funktionen wollen ein char
fclose(datei);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/631063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631063</guid><dc:creator><![CDATA[Blackhawk]]></dc:creator><pubDate>Sun, 17 Oct 2004 19:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 19:18:35 GMT]]></title><description><![CDATA[<p>Hallo Blackhawk,</p>
<p>kann ich so mal versuchen, in die Datei kann ich schreiben, es funktioniert auch alles, nur das Datum und die Zeit kann ich nicht in die Datei schreiben, dann kommt die Fehlermeldung. Ich denke, weil das Format nicht stimmt, die Zeit hat das Format DateTime.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/631073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631073</guid><dc:creator><![CDATA[ahl]]></dc:creator><pubDate>Sun, 17 Oct 2004 19:18:35 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 19:56:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">TFileStream *file=new TFileStream(&quot;c:\\bla.txt&quot;,fmCreate);
TDateTime zeit=zeit.CurrentDateTime();
file-&gt;Write(DateTimeToStr(zeit).data(),19);
delete file;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/631102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631102</guid><dc:creator><![CDATA[_Meier]]></dc:creator><pubDate>Sun, 17 Oct 2004 19:56:02 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 21:56:07 GMT]]></title><description><![CDATA[<p>Also ich hab das so gelöst und es funktioniert:</p>
<pre><code class="language-cpp">// Includes, die du brauchst (neben BCB-Standard-Includes)
#include &lt;time.h&gt;
#include &lt;stdio.h&gt;

// Funktion zum Abspeichern
bool save_time_to_file(char* filename,AnsiString asFormat=&quot;&quot;)
{
  // Lokale Zeit einlesen
  time_t tTmp=time(0);
  tm* tmTmp=localtime(&amp;tTmp);
  tTmp.~time_t();

  // Wenn Datei nicht geöffnet/erzeugt werden konnte, false zurückliefern
  FILE* fp;
  if((fp=fopen(filename,&quot;w&quot;))==NULL)
  {
    delete fp;
    delete tmTmp;
    return false;
  }

  // Andernfalls Beschriftung vorbereiten
  AnsiString sTime, sSec, sMin, sHour, sDay, sMon;
  if(tmTmp-&gt;tm_sec&lt;10)
    sSec=&quot;0&quot;;
  if(tmTmp-&gt;tm_min&lt;10)
    sMin=&quot;0&quot;;
  if(tmTmp-&gt;tm_hour&lt;10)
    sHour=&quot;0&quot;;
  if(tmTmp-&gt;tm_mday&lt;10)
    sDay=&quot;0&quot;;
  if(tmTmp-&gt;tm_mon&lt;9)
    sMon=&quot;0&quot;;
  if(asFormat!=&quot;&quot;)
    sTime=StringReplace(
          StringReplace(
          StringReplace(
          StringReplace(
          StringReplace(
          StringReplace(asFormat,&quot;S&quot;,sSec+IntToStr(tmTmp-&gt;tm_sec),TReplaceFlags()&lt;&lt;rfReplaceAll),
          &quot;I&quot;,sMin+IntToStr(tmTmp-&gt;tm_min),TReplaceFlags()&lt;&lt;rfReplaceAll),
          &quot;H&quot;,sHour+IntToStr(tmTmp-&gt;tm_hour),TReplaceFlags()&lt;&lt;rfReplaceAll),
          &quot;D&quot;,sDay+IntToStr(tmTmp-&gt;tm_mday),TReplaceFlags()&lt;&lt;rfReplaceAll),
          &quot;M&quot;,sMon+IntToStr(tmTmp-&gt;tm_mon+1),TReplaceFlags()&lt;&lt;rfReplaceAll),
          &quot;Y&quot;,IntToStr(tmTmp-&gt;tm_year+1900),TReplaceFlags()&lt;&lt;rfReplaceAll);
  else
    sTime=sDay+IntToStr(tmTmp-&gt;tm_mday)
         +&quot;.&quot;
         +sMon+IntToStr(tmTmp-&gt;tm_mon+1)
         +&quot;.&quot;
         +IntToStr(tmTmp-&gt;tm_year+1900);
         +&quot; - &quot;
         +sHour+IntToStr(tmTmp-&gt;tm_hour)
         +&quot;:&quot;
         +sMin+IntToStr(tmTmp-&gt;tm_min)
         +&quot;:&quot;
         +sSec+IntToStr(tmTmp-&gt;tm_sec);

  // Datei beschreiben
  fwrite(sTime.c_str(),sTime.Length(),1,fp);

  // Datei schließen
  fclose(fp);

  // Speicher freigeben und Erfolg zurückgeben
  delete fp;
  delete tmTmp;
  return true;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/631176</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631176</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Sun, 17 Oct 2004 21:56:07 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 21:58:50 GMT]]></title><description><![CDATA[<p>Anhang: Erscheint im ersten Moment kompliziert/zu lang, aber Vorteil ist einfach, dass man das Format selbst bestimmen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/631178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631178</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Sun, 17 Oct 2004 21:58:50 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Sun, 17 Oct 2004 23:24:21 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">bool save_time_to_file(String &amp;filename,String &amp;format,TDateTime &amp;zeit)
{
   try
   {
      String text;
      DateTimeToString(text,format,zeit);
      TFileStream *file=new TFileStream(filename,fmCreate);
      file-&gt;Write(text.data(),format.Length());
      delete file;
      return true;
   }
   catch(...)
   {
      return false;
   }
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TDateTime aktzeit=aktzeit.CurrentDateTime();
   if(save_time_to_file(&quot;c:\\blabla.txt&quot;,&quot;hhnnssmmddyyyy&quot;,aktzeit)) Edit1-&gt;Text =&quot;gespeichert.&quot;;
   else Edit1-&gt;Text =&quot;Fehler beim Schreiben !&quot;;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/631200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631200</guid><dc:creator><![CDATA[_Meier]]></dc:creator><pubDate>Sun, 17 Oct 2004 23:24:21 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Mon, 18 Oct 2004 12:29:46 GMT]]></title><description><![CDATA[<p>Hab es jetzt erst mal so gelöst, ist aber nur für die Zeit:</p>
<p>//aktuelle Zeit erzeugen<br />
TDateTime DateTime;<br />
int time;<br />
time = (int) (1000*60*60*24* DateTime.CurrentTime()); //msekunden<br />
time = time/1000; //Zeit in Sekunden<br />
int sec=time % 60; //Sekunden<br />
time /=60;<br />
int min=time % 60; //Minuten<br />
time /=60;<br />
int hr=time; //Stunden</p>
<p>fprintf(Daten, &quot;%02d:%02d:%02d \n&quot;,hr,min,sec);</p>
<p>Ist eigentlich sehr einfach.<br />
Muss nur noch was haben für das Datum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/631524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631524</guid><dc:creator><![CDATA[ahl]]></dc:creator><pubDate>Mon, 18 Oct 2004 12:29:46 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Mon, 18 Oct 2004 13:00:17 GMT]]></title><description><![CDATA[<p>Anhand Deines ersten Codefragments:</p>
<pre><code class="language-cpp">ofstream datei;

datei.open(&quot;C:\\Wetterstation\\Daten.txt&quot; , ios_base::app);

datei&lt;&lt;Temperatur&lt;&lt;'\t'&lt;&lt;Luftdruck&lt;&lt;'\t'&lt;&lt;Feuchte&lt;&lt;'\t'&lt;&lt;Windstaerke&lt;&lt;'\t'&lt;&lt;t&lt;&lt;endl;
datei &lt;&lt; Now().FormatString(&quot;DD.MM.YYYY HH:NN:SS&quot;).c_str();

datei.close();
</code></pre>
<p>In die Headerdatei muß rein</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
using namespace std;
</code></pre>
<p>So, Schluß jetzt <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/631559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631559</guid><dc:creator><![CDATA[Peter]]></dc:creator><pubDate>Mon, 18 Oct 2004 13:00:17 GMT</pubDate></item><item><title><![CDATA[Reply to Time in txt-Datei schreiben on Mon, 18 Oct 2004 14:54:08 GMT]]></title><description><![CDATA[<p>@_Meier: OK, ich nehem meins zurpück... es geht offensichtlich immer kürzer <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> Naja, vermutlich war ich einfach nur zu müde *ausred*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/631701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/631701</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Mon, 18 Oct 2004 14:54:08 GMT</pubDate></item></channel></rss>