<?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[logfile erstellen]]></title><description><![CDATA[<p>Guten Abend zusammen,</p>
<p>ich habe innerhalb eines größeren Programms eine Funktion die ein Logfile erstellen soll. Die Funktion arbeitet aber sporadisch nicht richtig. D.h. manchmal wird ein logfile erstellt und manchmal nicht. Mir ist noch kein Zusammenhang aufgefallen wann es funktioniert und wann nicht. Der Rest des Programms arbeitet einwandfrei.</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">void write_to_logfile(char *command, char *direction)
{
  time_t rawtime;
  struct tm * timeinfo;
  time ( &amp;rawtime );
  timeinfo = localtime ( &amp;rawtime );

  logfile = fopen (&quot;./logfile&quot;,&quot;a+&quot;);

  fseek (logfile, 0, SEEK_END);
  fprintf (logfile, &quot;%.24s: %.2s [%-30.30s]\n&quot;,asctime (timeinfo), direction, command);
  fclose (logfile);
}
</code></pre>
<p>Ich arbeite auf Ubuntu mit QTCreator (QT4.5, g++ 4.3.3). Der Compiler liefert keine Fehler/Warnungen aus dieser Funktion.</p>
<p>Ich bin leider nicht wirklich fit in C++ und mit meinem Latein am Ende.</p>
<p>Vielen Dank schonmal für eure Hilfe!</p>
<p>Vg<br />
Mathias</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/253479/logfile-erstellen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 18:19:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/253479.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Nov 2009 22:06:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 22:06:36 GMT]]></title><description><![CDATA[<p>Guten Abend zusammen,</p>
<p>ich habe innerhalb eines größeren Programms eine Funktion die ein Logfile erstellen soll. Die Funktion arbeitet aber sporadisch nicht richtig. D.h. manchmal wird ein logfile erstellt und manchmal nicht. Mir ist noch kein Zusammenhang aufgefallen wann es funktioniert und wann nicht. Der Rest des Programms arbeitet einwandfrei.</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">void write_to_logfile(char *command, char *direction)
{
  time_t rawtime;
  struct tm * timeinfo;
  time ( &amp;rawtime );
  timeinfo = localtime ( &amp;rawtime );

  logfile = fopen (&quot;./logfile&quot;,&quot;a+&quot;);

  fseek (logfile, 0, SEEK_END);
  fprintf (logfile, &quot;%.24s: %.2s [%-30.30s]\n&quot;,asctime (timeinfo), direction, command);
  fclose (logfile);
}
</code></pre>
<p>Ich arbeite auf Ubuntu mit QTCreator (QT4.5, g++ 4.3.3). Der Compiler liefert keine Fehler/Warnungen aus dieser Funktion.</p>
<p>Ich bin leider nicht wirklich fit in C++ und mit meinem Latein am Ende.</p>
<p>Vielen Dank schonmal für eure Hilfe!</p>
<p>Vg<br />
Mathias</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802416</guid><dc:creator><![CDATA[matze251284]]></dc:creator><pubDate>Mon, 02 Nov 2009 22:06:36 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 22:14:34 GMT]]></title><description><![CDATA[<p>aber du willst c++ programmieren und nicht c?<br />
das, was du dort machst hat nämlich nix mit c++ zu tun - dafür aber ne ganze menge mehr mit c ;P</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802421</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 02 Nov 2009 22:14:34 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 22:19:35 GMT]]></title><description><![CDATA[<p>Ich weiß, mir liegt C eigentlich auch etwas mehr. Intuitiv orientiere ich mich daher eher an C als an C++.</p>
<p>Aber der Code sollte trotzdem passen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802424</guid><dc:creator><![CDATA[matze251284]]></dc:creator><pubDate>Mon, 02 Nov 2009 22:19:35 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 22:50:31 GMT]]></title><description><![CDATA[<p>matze251284 schrieb:</p>
<blockquote>
<p>Ich weiß, mir liegt C eigentlich auch etwas mehr. Intuitiv orientiere ich mich daher eher an C als an C++.</p>
<p>Aber der Code sollte trotzdem passen, oder?</p>
</blockquote>
<p>sieht nicht gerade so aus^^<br />
warte einfach, bis dich ein mod ins c unterforum verschiebt oder poste dort noch ma neu und sag hier bescheid...<br />
ich jedenfalls sehe zwar, was der code tun soll, aber kann dir nicht sagen, wo der fehler liegen könnte, weils eben c ist : P</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802441</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 02 Nov 2009 22:50:31 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:01:11 GMT]]></title><description><![CDATA[<p>Wie würde man denn sowas in C++ lösen? Zwei drei Anhaltspunkte reichen, dann versuch ichs selber zusammenzubasteln...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802443</guid><dc:creator><![CDATA[matze251284]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:01:11 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:03:57 GMT]]></title><description><![CDATA[<p>1. <a href="http://www.cplusplus.com/reference/" rel="nofollow">http://www.cplusplus.com/reference/</a><br />
2. std::ofstream bzw std::fstream<br />
2. b) std::ios_base (app oder ate - weiß ich nie^^)<br />
3. std::localtime<br />
4. std::stringstream<br />
5. std::string</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802444</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:03:57 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:25:17 GMT]]></title><description><![CDATA[<p>Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802455</guid><dc:creator><![CDATA[matze251284]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:26:30 GMT]]></title><description><![CDATA[<p>np - ich hoffe, es sind genug stichpkt für dich^^<br />
kannst ja (am ende) mal zeigen, was du produziert hast^^</p>
<p>bd</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802456</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:26:30 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:31:28 GMT]]></title><description><![CDATA[<p>Es gibt da übrigens auch noch ein Standardstreamobjekt mit dem schönen Namen clog. Rate mal, wozu man das nutzen kann :). Geht allerdings in den meisten Fällen erstmal nach stderr, aber man kann ja entweder clog oder stderr in eine Datei umlenken, wenn man will.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802458</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:31:28 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Mon, 02 Nov 2009 23:39:35 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Es gibt da übrigens auch noch ein Standardstreamobjekt mit dem schönen Namen clog. Rate mal, wozu man das nutzen kann :). Geht allerdings in den meisten Fällen erstmal nach stderr, aber man kann ja entweder clog oder stderr in eine Datei umlenken, wenn man will.</p>
</blockquote>
<p>geht es nicht nach stdout ?<br />
ich dachte bisher, das wären die defaults:<br />
std::cerr =&gt; /dev/stderr<br />
std::cout =&gt; /dev/stdout<br />
std::clog =&gt; /dev/stdout<br />
std::cin =&gt; /dev/stdin</p>
<p>Egal, wie nun der default ist, das vorgehen ist sehr simpel, wie gesagt wurde:</p>
<p>ofstream objekt erstellen, std::clog dahin umleiten &lt;- am besten beim programm init<br />
Dann kannst überall std::clog &lt;&lt; &quot;Log Messsage&quot;; nutzen.<br />
Wenn du jetz aber automatisch in der Logfile die time haben willst,<br />
dann kannst von std::ofstream ableiten und das schreiben überladen, sodass erstmal ne time vorne dran gehängt wird.</p>
<p>Das wäre der C++ weg ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802461</guid><dc:creator><![CDATA[branleb]]></dc:creator><pubDate>Mon, 02 Nov 2009 23:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to logfile erstellen on Tue, 03 Nov 2009 00:31:55 GMT]]></title><description><![CDATA[<p>allerdings braucht man einen manipulator ähnlich wie std::endl...<br />
`my_logg &lt;&lt; &quot;asd = &quot; &lt;&lt; asd() &lt;&lt; &quot;\r\n&quot;;</p>
<p>my_logg &lt;&lt; &quot;def = &quot; &lt;&lt; def() &lt;&lt; &quot;\r\n&quot;;<code>würde ja entweder gar nicht oder nach jedem &lt;&lt; die zeit angeben... also bräuchte man intern noch nen bool, der anzeigt, ob die zeit eingefügt werden soll der wird beim erstellen auf true gesetzt und ansonsten nach jedem</code>endl` (bzw nach jedem flush.)<br />
was eleganteres fällt mir hier gerade nicht wirklich ein...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1802468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1802468</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 03 Nov 2009 00:31:55 GMT</pubDate></item></channel></rss>