<?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[GetCurrentTime() - Ein kleines Problem]]></title><description><![CDATA[<p>Guten Morgen an Alle</p>
<p>Ich habe mich an einem Programm versucht, das im 10-Sekunden-Takt<br />
mir die Zeit in Millisekunden ansagt mit</p>
<pre><code class="language-cpp">GetCurrentTime()
</code></pre>
<p>Aber ers wird jetzt jede Milisekunde angezeigt ...Ungewollt!</p>
<p>Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;Windows.h&gt;

using namespace std;

int main()
{
	static DWORD time;

	do
	{

	    time = GetCurrentTime();
		const DWORD time2 = GetCurrentTime(); + 10000;
        if (time2 == time)
		{
			cout &lt;&lt; GetCurrentTime() &lt;&lt; endl;
		}
	}while(time != 0);

	system(&quot;pause&quot;);
	return 0;
}
</code></pre>
<p>Bitte um Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290031/getcurrenttime-ein-kleines-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 18:46:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290031.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 18 Jul 2011 10:56:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 10:56:15 GMT]]></title><description><![CDATA[<p>Guten Morgen an Alle</p>
<p>Ich habe mich an einem Programm versucht, das im 10-Sekunden-Takt<br />
mir die Zeit in Millisekunden ansagt mit</p>
<pre><code class="language-cpp">GetCurrentTime()
</code></pre>
<p>Aber ers wird jetzt jede Milisekunde angezeigt ...Ungewollt!</p>
<p>Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;Windows.h&gt;

using namespace std;

int main()
{
	static DWORD time;

	do
	{

	    time = GetCurrentTime();
		const DWORD time2 = GetCurrentTime(); + 10000;
        if (time2 == time)
		{
			cout &lt;&lt; GetCurrentTime() &lt;&lt; endl;
		}
	}while(time != 0);

	system(&quot;pause&quot;);
	return 0;
}
</code></pre>
<p>Bitte um Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094202</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Mon, 18 Jul 2011 10:56:15 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:03:20 GMT]]></title><description><![CDATA[<p>das nimmt dein compiler??</p>
<p>da steht, dass du dir die aktuelle zeit holst und dann willst du 10000ms drauf addieren. das vergleichst du danach mit deinem vormals gemachten timestamp<br />
das kann nicht gutgehen, abgesehen davon, dass du dir die tiemstamps jeden schleifendurchlauf holst und die alten werte überschreibst...</p>
<pre><code class="language-cpp">int main()
{
    long t1=0, t2 = 10000;
    while ( true )
    {
        t2 = GetCurrentTime();
        if ( t2 &gt;= t1+10000 ) {
            cout &lt;&lt; GetCurrentTime() &lt;&lt; endl;
            t1 = GetCurrentTime();
        }
    }
    return 0x0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2094203</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094203</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:03:20 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:11:26 GMT]]></title><description><![CDATA[<p>Danke hat geholfen!! <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="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094205</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:11:26 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:37:43 GMT]]></title><description><![CDATA[<p>Hab diese funktion mal lange her geschrieben:</p>
<p>Bitte beachte, dass diese funktion MIRCO-, und nicht MILLI-sekunden zurückgibt.<br />
Du wirst auch ein paar header brauchen wie time.h (oder sys/time.h)</p>
<p><s>EDIT &amp; EDIT2: Sorry, free() ist jetzt auch drin.</s><br />
<strong>EDIT3: Ist jetzt auf dem Stack. Kein static mehr. Ungetestet, sollte aber gehen.</strong></p>
<pre><code class="language-cpp">// returns MIRCOSECONDS
long xtime()
{
    timeval tv;
    gettimeofday(&amp;tv, NULL);
    return tv.tv_usec + (tv.tv_sec*1000000);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2094206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094206</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:37:43 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:16:06 GMT]]></title><description><![CDATA[<p>Funzt auch gut !!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094213</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:16:06 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:30:07 GMT]]></title><description><![CDATA[<p>funktioniert nicht gut !!!!</p>
<p>das ist ein memory leak, wann wird denn diese statische variable gelöscht, bzw der speicher dahinter</p>
<p>pack dein tv einfach in einen auto_ptr (shared_ptr ist zuviel) und danach guckst du mal in scott meyers effektiv c++ programming kapitel 3.1 (tipp 13) in der aktuellen auflage(3. auflage erschienen anfang 2011) durch ! oder gleich das ganze buch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094221</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:30:07 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:35:20 GMT]]></title><description><![CDATA[<p>lk schrieb:</p>
<blockquote>
<p>Hab diese funktion mal lange her geschrieben:</p>
<p>Bitte beachte, dass diese funktion MIRCO-, und nicht MILLI-sekunden zurückgibt.<br />
Du wirst auch ein paar header brauchen wie time.h (oder sys/time.h)</p>
<pre><code class="language-cpp">// returns MIRCOSECONDS
long xtime()
{
    static timeval *tv = (timeval*)malloc(sizeof(timeval));
    gettimeofday(tv, NULL);
    return tv-&gt;tv_usec + (tv-&gt;tv_sec*1000000);
}
</code></pre>
</blockquote>
<p>1. Wo wird free(..) aufgerufen?<br />
2. malloc(..) ist nicht nötig (Punkt 1 erübrigt sich dann)<br />
3. Warum zur Hölle static? Es ist nicht sinnvoll/nötig!<br />
4. Falls static Thread-Safty? (Erübrigt sich wegen Punkt 3.)</p>
<p><strong>Edit:</strong></p>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>pack dein tv einfach in einen auto_ptr (shared_ptr ist zuviel) und danach guckst du mal in scott meyers effektiv c++ programming kapitel 3.1 (tipp 13) in der aktuellen auflage(3. auflage erschienen anfang 2011) durch ! oder gleich das ganze buch</p>
</blockquote>
<p>Warum zur Hölle soll das auf dem Heap landen??? Völlig unnötig!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094224</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094224</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 11:44:47 GMT]]></title><description><![CDATA[<p>theta schrieb:</p>
<blockquote>
<p>lk schrieb:</p>
<blockquote>
<p>Hab diese funktion mal lange her geschrieben:</p>
<p>Bitte beachte, dass diese funktion MIRCO-, und nicht MILLI-sekunden zurückgibt.<br />
Du wirst auch ein paar header brauchen wie time.h (oder sys/time.h)</p>
<pre><code class="language-cpp">// returns MIRCOSECONDS
long xtime()
{
    static timeval *tv = (timeval*)malloc(sizeof(timeval));
    gettimeofday(tv, NULL);
    return tv-&gt;tv_usec + (tv-&gt;tv_sec*1000000);
}
</code></pre>
</blockquote>
<p>1. Wo wird free(..) aufgerufen?<br />
2. malloc(..) ist nicht nötig (Punkt 1 erübrigt sich dann)<br />
3. Warum zur Hölle static? Es ist nicht sinnvoll/nötig!<br />
4. Falls static Thread-Safty? (Erübrigt sich wegen Punkt 3.)</p>
<p><strong>Edit:</strong></p>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>pack dein tv einfach in einen auto_ptr (shared_ptr ist zuviel) und danach guckst du mal in scott meyers effektiv c++ programming kapitel 3.1 (tipp 13) in der aktuellen auflage(3. auflage erschienen anfang 2011) durch ! oder gleich das ganze buch</p>
</blockquote>
<p>Warum zur Hölle soll das auf dem Heap landen??? Völlig unnötig!!!</p>
</blockquote>
<p>Ich bin eben ein stack verabscheuer. Das errinnert mich an Steak, und die verabscheue ich auch.</p>
<p>Zu 1: war im 1. Edit beseitigt.<br />
2: beseitigt im 3. Edit.<br />
3: Ist ja schon aufm Stack.<br />
4: Deswegen wollte meine multithreading anwendung immer abschtürzen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094230</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Mon, 18 Jul 2011 11:44:47 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 13:04:30 GMT]]></title><description><![CDATA[<p>lk schrieb:</p>
<blockquote>
<p>Ich bin eben ein stack verabscheuer. Das errinnert mich an Steak, und die verabscheue ich auch.</p>
</blockquote>
<p>dann lern es mal zu schätzen der stack ist saupraktisch und noch mehr sauschneller (;)) und steaks sind auch cool <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>lk schrieb:</p>
<blockquote>
<p>4: Deswegen wollte meine multithreading anwendung immer abschtürzen!</p>
</blockquote>
<p>wieso hab ich das gefühl, dass du nicht ganz weisst was du tust?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094274</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 18 Jul 2011 13:04:30 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 13:13:28 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>lk schrieb:</p>
<blockquote>
<p>4: Deswegen wollte meine multithreading anwendung immer abschtürzen!</p>
</blockquote>
<p>wieso hab ich das gefühl, dass du nicht ganz weisst was du tust?!</p>
</blockquote>
<p>Vielleicht weil ich an der Uni gerade mit Java gequält werde, und ich C/C++ sehr lange nicht mehr gesehen habe...?</p>
<p>bin dafür diese Diskussion jetzt zu schließen, da sie zu sehr offtopic ist. (Und peinlich auch, insbesondere für mich... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094283</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Mon, 18 Jul 2011 13:13:28 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 13:58:44 GMT]]></title><description><![CDATA[<p>java ist eigentlich nicht schlecht, weil da übernehmen andere das denken, z.b. die java entwickler und daraus resultierend die compiler/runtime-environments und so</p>
<p>find ich irgendwo doof wenn man jetzt total ineffezienten programmcode schreibt und der so vom compiler optimiert und heruntergebrochen wird, dass der byte code nach ein paar jahren schneller läuft als jedes C/C++ programm, und auch noch paralleles rechnen automatisch mit eingebracht wird...<br />
bald werden wohl computer und betriebssysteme von kindern und DAU's selbst programmiert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094304</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 18 Jul 2011 13:58:44 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 16:01:07 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>java ist eigentlich nicht schlecht, weil da übernehmen andere das denken, z.b. die java entwickler und daraus resultierend die compiler/runtime-environments und so</p>
</blockquote>
<p>Naja, manche Leute halten Java gerade deswegen für schlecht <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>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>find ich irgendwo doof wenn man jetzt total ineffezienten programmcode schreibt und der so vom compiler optimiert und heruntergebrochen wird, dass der byte code nach ein paar jahren schneller läuft als jedes C/C++ programm</p>
</blockquote>
<p>Ich glaube, du machst dir unnötige Sorgen. Zudem muss man auch in Java etwas können, obwohl die Sprache es natürlich leichter als C++ macht, mit wenig Wissen was zustande zu bringen. Für qualitativ hochwertige Software braucht es aber auch hier einiges an Erfahrung...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094358</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 18 Jul 2011 16:01:07 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 16:14:25 GMT]]></title><description><![CDATA[<p>So ich habe mich jetzt mal an einem Programm versucht (mit wenigen euer Codestücke)<br />
Aber es macht nicht ganz was es soll-.-<br />
Es soll kontinuirlich im 1-Sekunden-Takt Daten aus einem bestimmten Ordner löschen und man soll bestätigen das man die Datei löscht.</p>
<p>Aber es löscht nur bei Programmstart die Dateien und fragt auch wenn die Datei schon gelöscht wurde immer wieder ob man die Datei löschen will<br />
Hier der Code:</p>
<pre><code class="language-cpp">void ShowFiles(const char *path,const char *files)
{
  SetCurrentDirectory(path);
  WIN32_FIND_DATA fileData;
  HANDLE hFind = FindFirstFile(files, &amp;fileData);

long t1=0, t2 = 1000;
    while ( true )
    {
        t2 = GetCurrentTime();
        if ( t2 &gt;= t1+1000 ) 
		{

           if (hFind != INVALID_HANDLE_VALUE)
           {

                do 
	            {
                   if (fileData.dwFileAttributes &amp; ~FILE_ATTRIBUTE_DIRECTORY)
                   { 
					   cout &lt;&lt; &quot;M&quot;&lt;&lt;char(148)&lt;&lt;&quot;chten sie wirklich die Datei &quot; &lt;&lt; fileData.cFileName &lt;&lt; &quot; L&quot;&lt;&lt;char(148)&lt;&lt;&quot;schen?&quot; &lt;&lt; endl;
					     cin.get();
	                    remove(fileData.cFileName);
						cout &lt;&lt; &quot;Datei wurde gelöscht!&quot; &lt;&lt; endl;
	               }
                } while (FindNextFile(hFind, &amp;fileData));
	       }
		   t1 = GetCurrentTime();
       }

    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2094371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094371</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Mon, 18 Jul 2011 16:14:25 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 18:26:59 GMT]]></title><description><![CDATA[<p>Bist du sicher, dass FindNextFile noch korrekt arbeitet, wenn die Datei, von der die Suche fortgesetzt werden soll, gelöscht wurde?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094474</guid><dc:creator><![CDATA[GyroGearloose]]></dc:creator><pubDate>Mon, 18 Jul 2011 18:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 20:04:19 GMT]]></title><description><![CDATA[<p>Ach mist ^^<br />
aber ich habe keine ahnung wie ich das bewerkstelligen soll ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094540</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Mon, 18 Jul 2011 20:04:19 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 20:16:07 GMT]]></title><description><![CDATA[<p>Ich kenne mich mit FindFirstFile und FindNextFile auch nicht so aus.</p>
<p>Aber du könntest z. B. erst mit den beiden Funktionen alle Dateinamen bzw. -pfade sammeln, in einem Container speichern und erst danach den Container durchgehen und die einzelnen Datei löschen und das Löschen vom Anwender bestätigen lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094545</guid><dc:creator><![CDATA[GyroGearloose]]></dc:creator><pubDate>Mon, 18 Jul 2011 20:16:07 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Mon, 18 Jul 2011 22:17:17 GMT]]></title><description><![CDATA[<p>Was du da machst ist nicht gerade CPU-schonend. Wozu willst du überhaupt so lange warten? Soll der Programmierer das Gefühl bekommen, dass deine Funktion viel arbeitet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094587</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 18 Jul 2011 22:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 08:56:40 GMT]]></title><description><![CDATA[<p>Einfach nur aus demonstrativen Zwecken es soll ja kein fertiges Programm werden, sondern nur ein Prototyp ...</p>
<p>Aber ich weiß nichts über Container <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094681</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Tue, 19 Jul 2011 08:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 08:59:19 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/stl/" rel="nofollow">hier</a> oder <a href="http://www.c-plusplus.net/forum/143816" rel="nofollow">hier</a></p>
<p>die sind nicht nur extremst hilfreich sondern auch sehr wichtig weil sie flott sind und dir das gesamte leben ziemlich erleichtern</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094682</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Tue, 19 Jul 2011 08:59:19 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 09:21:46 GMT]]></title><description><![CDATA[<p>Jetzt bleib nur die Frage welche Container List, Maps oder multimaps<br />
Und füge ich einzelne Daten jeweils hinzu um sie Dann zu löschen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094695</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Tue, 19 Jul 2011 09:21:46 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 09:37:37 GMT]]></title><description><![CDATA[<p><a href="http://linuxsoftware.co.nz/containerchoice.png" rel="nofollow">welcher container?!?</a></p>
<p>da suchste dir einen aus und dann guckst du auf dem ersten link wie er benutzt wird...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094705</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Tue, 19 Jul 2011 09:37:37 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 09:53:10 GMT]]></title><description><![CDATA[<p>Danke ^^!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2094716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2094716</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Tue, 19 Jul 2011 09:53:10 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 17:48:58 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void ShowFiles(const char *path,const char *files)
{
  SetCurrentDirectory(path);
  WIN32_FIND_DATA fileData;
  HANDLE hFind = FindFirstFile(files, &amp;fileData);

  list&lt;WIN32_FIND_DATA&gt; lLöschen;
  list&lt;WIN32_FIND_DATA&gt;::iterator i;

long t1=0, t2 = 10;
    while ( true )
    {
        t2 = GetCurrentTime();
        if ( t2 &gt;= t1+10 ) 
		{

           if (hFind != INVALID_HANDLE_VALUE)
           {

                do 
	            {
                   if (fileData.dwFileAttributes &amp; ~FILE_ATTRIBUTE_DIRECTORY)
                   { 

					   lLöschen.push_back(fileData);
					   for (i = lLöschen.begin() ;i != lLöschen.end(); i++)
					   {
						   remove(fileData.cFileName);
	                   }
				   }
                } while (FindNextFile(hFind, &amp;fileData));

		   t1 = GetCurrentTime();
       }

    }
 }
}
</code></pre>
<p>Ich glaube ich bin einfach zu doof dafür <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Edit: Jetzt löscht es am Anfang die Dateien aber man kann gar keine Dateien mehr in diesem Ordner erstellen!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2095042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2095042</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Tue, 19 Jul 2011 17:48:58 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 18:24:09 GMT]]></title><description><![CDATA[<p>nein er meint das etwas anders mit dem im container speichern...</p>
<p>du sollst erst per schleife den verzeichnis iterator durchgehen und jedes file in deinem container speichern(oder halt einen zeiger/referenz darauf) und danach sollst du alles was in diesem container ist löschen</p>
<p>beim löschen von und mit iteratoren muss man etwas aufpassen, die können schnell ungültig werden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2095059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2095059</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Tue, 19 Jul 2011 18:24:09 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 19:01:22 GMT]]></title><description><![CDATA[<p>crashjosh schrieb:</p>
<blockquote>
<p>Ich glaube ich bin einfach zu doof dafür <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Ach, ruhig bleiben. Du musst dein Problem (wie eigentlich immer) nur in kleinere Teilproblemchen teilen.</p>
<p>Der Sinn, jede Sekunde eine Datei zu löschen, erschließt sich mir zwar nicht, aber du könntest am Anfang erst einmal eine Struktur definieren, die jederzeit (Dateigröße, Erstellungs-/Änderungs/(letzte Zugriffs)-Zeit) erweiterbar ist.</p>
<pre><code class="language-cpp">struct FileInfo
{
	enum Type {DIR, FILE, INVALID};

	FileInfo(const char* name, Type t) : filename(name),type(t) {};
	FileInfo(const FileInfo&amp; rhs)
	{
		*this=rhs;
	}
	~FileInfo() { }
	FileInfo&amp; operator=(const FileInfo&amp; rhs)
	{
		filename = rhs.filename;
		type=rhs.type;
		return *this;
	}

	Type type;
	string filename;
};
</code></pre>
<p>Dann eine Funktion schreiben, die das Verzeichnis einliest:</p>
<pre><code class="language-cpp">bool GetDir(const char* name, vector&lt;FileInfo&gt;&amp; v, bool subfolders = false)
{
	WIN32_FIND_DATA data;
	string dir = name;
	dir+=&quot;/*&quot;;
	HANDLE hdl=FindFirstFile(dir.c_str(), &amp;data);
	if(hdl==INVALID_HANDLE_VALUE)
		return false;
	do
	{
		if(!((data.cFileName[0]=='.') &amp;&amp; ( (data.cFileName[1]=='.' &amp;&amp; data.cFileName[2]==0) || data.cFileName[1]==0)))
		{ 
			string path = name;
			path+='\\';
			path+=data.cFileName;
			if(data.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
			{
				v.push_back(FileInfo(path.c_str(), FileInfo::DIR));
				if(subfolders)
				{
					string dir = name;
					dir+='\\';
					dir+=data.cFileName;
					GetDir(dir.c_str(), v, true); // rekursiv aufrufen
				}
			}
			else
			{
				v.push_back(FileInfo(path.c_str(), FileInfo::FILE));
			}
		}
	}while(FindNextFile(hdl,&amp;data));

	FindClose(hdl);
	return true;
}
</code></pre>
<p>Somit kannst du alle Dateien eines Verzeichnisses (auch sämtlicher Unterverzeichnisse) in Erfahrung bringen, sortieren, löschen, ausführen etc..</p>
<p>Ich habe eine ähnliche FileInfo-Klasse, musste diese jedoch aus nachvollziehbaren Gründen kürzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2095070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2095070</guid><dc:creator><![CDATA[yahendrik]]></dc:creator><pubDate>Tue, 19 Jul 2011 19:01:22 GMT</pubDate></item><item><title><![CDATA[Reply to GetCurrentTime() - Ein kleines Problem on Tue, 19 Jul 2011 19:16:42 GMT]]></title><description><![CDATA[<p>Danke für den ausfürhlichen Code!!<br />
Welche Paramter kommen denn bei GetDir(&quot;C:\*&quot;,...,...) noch rein ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2095079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2095079</guid><dc:creator><![CDATA[crashjosh]]></dc:creator><pubDate>Tue, 19 Jul 2011 19:16:42 GMT</pubDate></item></channel></rss>