<?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[Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100)]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich arbeite gerade ein C++-Tutorial durch und bin noch sehr weit am Anfang. Als Aufgabe soll hier ein Programm geschrieben werden, dass alle Primzahlen von 2 bis 100 aufzählt. Wenn ich das Programm bei mir starte, dann zählt das Programm allerdings alle Zahlen von 2 bis 100 auf und nicht nur die Primzahlen. Nachdem ich schon ewig den Fehler suche und kleine Änderungen vornehme, muss ich jetzt aufgeben, es sei denn jemand von euch kann mir helfen.</p>
<p>Falls Ihr mehr Infos braucht, sagt einfach Bescheid.</p>
<p>Danke schon mal im Voraus</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;

using namespace std;

bool istPrim(int Zahl);

int main()
{  
  bool Prim;
  int Zahl=2;

  while (Zahl&lt;=100)
  {
        Prim=istPrim(Zahl);
        if(Prim=true)
          cout&lt;&lt;Zahl&lt;&lt;&quot; ist eine Primzahl&quot;&lt;&lt;endl;
        else
        ;
        Zahl=Zahl+1;
  };

  system(&quot;PAUSE&quot;);

  return 0;   
};

bool istPrim(int Zahl)
{
     bool Prim=true;

     for (int i=2;i&lt;=Zahl-1;i=i+1)
     {
         if(Zahl%i==0)
          {
            Prim=false;
            break;
          }
     }  
  return Prim;  
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/304403/probleme-bei-tutorial-programm-zur-auflistung-aller-primzahlen-von-1-bis-100</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 07:51:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304403.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Jun 2012 13:46:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 13:46:30 GMT]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich arbeite gerade ein C++-Tutorial durch und bin noch sehr weit am Anfang. Als Aufgabe soll hier ein Programm geschrieben werden, dass alle Primzahlen von 2 bis 100 aufzählt. Wenn ich das Programm bei mir starte, dann zählt das Programm allerdings alle Zahlen von 2 bis 100 auf und nicht nur die Primzahlen. Nachdem ich schon ewig den Fehler suche und kleine Änderungen vornehme, muss ich jetzt aufgeben, es sei denn jemand von euch kann mir helfen.</p>
<p>Falls Ihr mehr Infos braucht, sagt einfach Bescheid.</p>
<p>Danke schon mal im Voraus</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;

using namespace std;

bool istPrim(int Zahl);

int main()
{  
  bool Prim;
  int Zahl=2;

  while (Zahl&lt;=100)
  {
        Prim=istPrim(Zahl);
        if(Prim=true)
          cout&lt;&lt;Zahl&lt;&lt;&quot; ist eine Primzahl&quot;&lt;&lt;endl;
        else
        ;
        Zahl=Zahl+1;
  };

  system(&quot;PAUSE&quot;);

  return 0;   
};

bool istPrim(int Zahl)
{
     bool Prim=true;

     for (int i=2;i&lt;=Zahl-1;i=i+1)
     {
         if(Zahl%i==0)
          {
            Prim=false;
            break;
          }
     }  
  return Prim;  
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2219783</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219783</guid><dc:creator><![CDATA[jango157]]></dc:creator><pubDate>Tue, 05 Jun 2012 13:46:30 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 13:56:38 GMT]]></title><description><![CDATA[<p>Zeile 16: if( Prim == true ) // muss '==' statt '=' heißen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219790</guid><dc:creator><![CDATA[Werner_logoff]]></dc:creator><pubDate>Tue, 05 Jun 2012 13:56:38 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 13:59:35 GMT]]></title><description><![CDATA[<p>jango157 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(Prim=true)
</code></pre>
</blockquote>
<p>ist die Wurzel allen übels. Das muss <code>Prim == true</code> heißen.<br />
Abgesehen davon: hast du den Code 1:1 vom Tutorial kopiert? Konstrukte wie <code>... &lt;= Zahl -1</code> machen mir irgendwie Angst...</p>
<p>EDIT: Menno, wär ich nur 22 Sekunden schneller gewesen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219791</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Tue, 05 Jun 2012 13:59:35 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 14:00:41 GMT]]></title><description><![CDATA[<p>Hi.</p>
<p>Zeile 16: Du machst eine Zuweisung, keinen Vergleich (= statt ==)</p>
<p>gruß<br />
syntax</p>
<p>[EDIT] Wenn der Lehrer nicht immer die Runde gehen würde, wär isch der schnellste gewesen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
<p>gruß<br />
syntax</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219794</guid><dc:creator><![CDATA[Syntax_error]]></dc:creator><pubDate>Tue, 05 Jun 2012 14:00:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 14:08:24 GMT]]></title><description><![CDATA[<p>Apropos der Schnellste:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\n&quot;;
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219806</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 14:08:24 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 14:12:13 GMT]]></title><description><![CDATA[<p>Hallo,<br />
also erstmal Ihr seid ja echt der Hammer! Großes Kompliment von mir für die extrem schnellen Antworten (Und dann auch noch die Richtigen!!!).</p>
<p>Und zur möglichen 1:1 Kopie. Nachdem mein vollkommen selbst geschriebenes progrämmchen nicht funktioniert hat, habe ich mich tatsächlich immer mehr dem vorgegeben Teil aus dem Tutorial angenähert (zumindest bei der Funktion unten).</p>
<p>PS: warum macht dir &lt;=Zahl-1 Angst?</p>
<p>Vielen vielen dank an alle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219814</guid><dc:creator><![CDATA[jango157]]></dc:creator><pubDate>Tue, 05 Jun 2012 14:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 14:21:30 GMT]]></title><description><![CDATA[<p>jango157 schrieb:</p>
<blockquote>
<p>PS: warum macht dir &lt;=Zahl-1 Angst?</p>
<p>Vielen vielen dank an alle</p>
</blockquote>
<p>Mir machts zwar keine Angst, aber ich finde &lt;Zahl schöner und kürzer. <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>gruß<br />
syntax</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219824</guid><dc:creator><![CDATA[Syntax_error]]></dc:creator><pubDate>Tue, 05 Jun 2012 14:21:30 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 14:33:25 GMT]]></title><description><![CDATA[<p>Ich finde &lt; Zahl auch schöner. Und was nicht schön ist macht mir Angst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Abgesehen davon:</p>
<pre><code class="language-cpp">if(...)
    cout &lt;&lt; &quot;foo&quot;;
else
;
</code></pre>
<p>Das ist auch unschön. Das else dürfte zwar von jedem schlauen Compiler wegoptimiert werden, aber warum schreibst du das überhaupt hin um dann ne leere Anweisung draus zu machen?</p>
<p>EDIT:</p>
<pre><code class="language-cpp">Zahl=Zahl+1;
</code></pre>
<p>Auch unschön.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219831</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Tue, 05 Jun 2012 14:33:25 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 16:00:43 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Apropos der Schnellste:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\n&quot;;
</code></pre>
<p>?</p>
</blockquote>
<p>Kann ich überbieten:</p>
<pre><code class="language-cpp">puts(&quot;2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\n&quot;);
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219888</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 05 Jun 2012 16:00:43 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 16:07:50 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Kann ich überbieten:</p>
</blockquote>
<p>Das würde ich mal messen (mein Rechner ist aber im Moment zu ausgelastet für Benchmarks). ostream::operator&lt;&lt; ist schließlich überladen für C-Strings, daher sollte das eigentlich das gleiche sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219892</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 16:07:50 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 16:12:15 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>hustbaer schrieb:</p>
<blockquote>
<p>Kann ich überbieten:</p>
</blockquote>
<p>Das würde ich mal messen (mein Rechner ist aber im Moment zu ausgelastet für Benchmarks). ostream::operator&lt;&lt; ist schließlich überladen für C-Strings, daher sollte das eigentlich das gleiche sein.</p>
</blockquote>
<p>Es ging glaub' ich nicht um die Geschwindigkeit sondern um die Anzahl der Zeichen...</p>
<p>Abgesehen davon muss die Aufgabe ja <em>Berechnung aller Primzahlen von ...</em> heißen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219895</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219895</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 05 Jun 2012 16:12:15 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 16:51:15 GMT]]></title><description><![CDATA[<p>Nö mir ging's schon um die Geschwindigkeit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>SeppJ schrieb:</p>
<blockquote>
<p>hustbaer schrieb:</p>
<blockquote>
<p>Kann ich überbieten:</p>
</blockquote>
<p>Das würde ich mal messen (mein Rechner ist aber im Moment zu ausgelastet für Benchmarks). ostream::operator&lt;&lt; ist schließlich überladen für C-Strings, daher sollte das eigentlich das gleiche sein.</p>
</blockquote>
<p>Na gut, dann halt</p>
<pre><code class="language-cpp">static const char tfpnutoh[] = &quot;2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\n&quot;;
fwrite(tfpnutoh, 1, sizeof(tfpnutoh) - 1, stdout);
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219903</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 05 Jun 2012 16:51:15 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 17:01:28 GMT]]></title><description><![CDATA[<p>Jetzt kommen wir dem Ziel einer nicht nur absichtlich falsch verstandenen sondern auch absolut unleserlichen Lösung näher. <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>
<p>P.S.: In C++ natürlich cout.write(...). Den dadurch erzeugten Overhead beim Startup für die Konstruktion des cout-Objektes würde nicht nicht mitzählen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219908</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 17:01:28 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 18:14:59 GMT]]></title><description><![CDATA[<p>Ich glaub nicht das er noch irgendwas von dem Zeugs versteht, was ihr schreibt :p .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219939</guid><dc:creator><![CDATA[IrgendeinName]]></dc:creator><pubDate>Tue, 05 Jun 2012 18:14:59 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 18:19:50 GMT]]></title><description><![CDATA[<p>Da sein Problem ja schon gelöst wurde, sollte das OK gehen. Behaupte ich mal. Wenn nicht einfach schreien.</p>
<p>Man könnte jetzt ne TMP Version basteln. Also komplett inklusive Konvertierung ins Dezimalsystem und Konkatenierung der Ergebnisse.</p>
<pre><code class="language-cpp">fwrite(black_template_magic_primes&lt;100&gt;::str, 1, black_template_magic_primes&lt;100&gt;::strlen, stdout);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2219941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219941</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 05 Jun 2012 18:19:50 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 18:35:17 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Da sein Problem ja schon gelöst wurde, sollte das OK gehen. Behaupte ich mal. Wenn nicht einfach schreien.</p>
<p>Man könnte jetzt ne TMP Version basteln. Also komplett inklusive Konvertierung ins Dezimalsystem und Konkatenierung der Ergebnisse.</p>
<pre><code class="language-cpp">fwrite(black_template_magic_primes&lt;100&gt;::str, 1, black_template_magic_primes&lt;100&gt;::strlen, stdout);
</code></pre>
</blockquote>
<p>Mein Unnötigkeitssensor schlägt wieder aus... oha, 6.9 - ich glaube gar, hustbaer sitzt da wirklich dran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219954</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 05 Jun 2012 18:35:17 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 18:52:31 GMT]]></title><description><![CDATA[<p>Hacker, überleg mal. Wie kann ein Sensor der - sich in deinem Besitz befindend - immer auf Anschlag steht noch weiter ausschlagen? Das kann nicht gehen.</p>
<p>Und nein, ich sitze da nicht dran.</p>
<p>Obwohl es auch nicht notwendigerweise &quot;unnötig&quot; wäre, zumindest nicht subjektiv betrachtet. Kann man einiges dabei lernen, bzw. üben wenn es Dinge sind die man schon kann, aber vielleicht länger nicht mehr angewendet hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219958</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 05 Jun 2012 18:52:31 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 18:56:48 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Hacker, überleg mal. Wie kann ein Sensor der - sich in deinem Besitz befindend - immer auf Anschlag steht noch weiter ausschlagen? Das kann nicht gehen.</p>
</blockquote>
<p>Ich hab Alufolie rumgewickelt und bediene das ding durch eine Angel und einen Stock, aber der Zeiger zittert immer noch ein bisschen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>Außerdem mach' ich eigentlich nie unnötige Sachen. Ich bin - in gewissen Zeiten - recht rational.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219961</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219961</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 05 Jun 2012 18:56:48 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 19:11:06 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Man könnte jetzt ne TMP Version basteln. Also komplett inklusive Konvertierung ins Dezimalsystem und Konkatenierung der Ergebnisse.</p>
</blockquote>
<p>Ei, das ist wirklich übel hart. Da bin ich mir selbst nach einigem Nachdenken nicht sicher, ob das überhaupt geht. Ich glaube man braucht aber mindestens variadic templates. Habe gerade keine Zeit, mir das genauer anzugucken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219967</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Jun 2012 19:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 19:14:16 GMT]]></title><description><![CDATA[<p>Variadic Templates waren noch nie erforderlich, sie sind einfach eine Vereinfachung für Typlisten, wie aus dem Alexandrescu bekannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219971</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 05 Jun 2012 19:14:16 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 20:02:53 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>sie sind einfach eine Vereinfachung für Typlisten, wie aus dem Alexandrescu bekannt.</p>
</blockquote>
<p>Das ist Sepp sicherlich bekannt. Aber es sind generische Typlisten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219988</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 05 Jun 2012 20:02:53 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 20:25:21 GMT]]></title><description><![CDATA[<p>Was soll denn bitte eine generische Typliste sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2219996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2219996</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 05 Jun 2012 20:25:21 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 20:34:53 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>Was soll denn bitte eine generische Typliste sein?</p>
</blockquote>
<p>Was ich meine ist folgendes: Ich dachte, du meinst, man kann statt</p>
<pre><code class="language-cpp">template&lt;typename ...c&gt;
void func(//.....
</code></pre>
<p>Auch gleich das aufzurufende einsetzen.</p>
<pre><code class="language-cpp">template&lt;char a, size_t s, char b&gt;
void func(//...
</code></pre>
<p>In diesem Fall ist aber (ich weiß nicht ob das Wort hier passt) oberes generischer, nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220001</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 05 Jun 2012 20:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 21:11:20 GMT]]></title><description><![CDATA[<p>Keine Ahnung, wovon du redest. Das hat damit überhaupt nichts zu tun. Hast du den Alexandrescu überhaupt gelesen? Falls nein -&gt; großer Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220027</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 05 Jun 2012 21:11:20 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Tue, 05 Jun 2012 23:03:59 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Ei, das ist wirklich übel hart. Da bin ich mir selbst nach einigem Nachdenken nicht sicher, ob das überhaupt geht.</p>
</blockquote>
<p>Bitteschön.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;type_traits&gt;

template &lt;bool B&gt;
struct bool_
	: std::integral_constant&lt;bool, B&gt;
{};

template &lt;unsigned I&gt;
struct unsigned_
	: std::integral_constant&lt;unsigned, I&gt;
{};

template &lt;typename A, typename B&gt;
struct dividable
	: bool_&lt;A::value % B::value == 0&gt;
{};

template &lt;typename A, typename B&gt;
struct or_
	: bool_&lt;A::value || B::value&gt;
{};

template &lt;typename I&gt;
struct increment
	: unsigned_&lt;I::value + 1&gt;
{};

template &lt;typename A, typename B&gt;
struct squared_less_equal
	: bool_&lt;(A::value * A::value &lt;= B::value)&gt;
{};

template &lt;typename A&gt;
struct not_
	: bool_&lt;!A::value&gt;
{};

template
&lt;
	template &lt;typename, typename&gt; class Func,
	typename Arg1
&gt;
struct bind1st
{
	template &lt;typename Arg2&gt;
	struct binder1st : Func&lt;Arg1, Arg2&gt;
	{};
};

template
&lt;
	template &lt;typename, typename&gt; class Func,
	typename Arg2
&gt;
struct bind2nd
{
	template &lt;typename Arg1&gt;
	struct binder2nd : Func&lt;Arg1, Arg2&gt;
	{};
};

template
&lt;
	typename Init,
	template &lt;typename&gt; class Cond,
	template &lt;typename&gt; class Next,
	template &lt;typename&gt; class Do,
	template &lt;typename, typename&gt; class Combine,
	typename Else
&gt;
struct for_
	: std::conditional
	&lt;
		Cond&lt;Init&gt;::value,
		typename std::conditional
		&lt;
			Cond&lt;Next&lt;Init&gt;&gt;::value,
			Combine
			&lt;
				Do&lt;Init&gt;,
				for_&lt;Next&lt;Init&gt;, Cond, Next, Do, Combine, Else&gt;
			&gt;,
			Do&lt;Init&gt;
		&gt;::type,
		Else
	&gt;::type
{};

template &lt;unsigned I&gt;
struct is_prime
	: not_
	&lt;
		for_
		&lt;
			unsigned_&lt;2&gt;,
			bind2nd&lt;squared_less_equal, unsigned_&lt;I&gt;&gt;::template binder2nd,
			increment,
			bind1st&lt;dividable, unsigned_&lt;I&gt;&gt;::template binder1st,
			or_,
			bool_&lt;true&gt;
		&gt;
	&gt;
{};

template &lt;&gt;
struct is_prime&lt;2&gt;
	: bool_&lt;true&gt;
{};

template &lt;&gt;
struct is_prime&lt;3&gt;
	: bool_&lt;true&gt;
{};

template &lt;char... S&gt;
struct string : std::identity&lt;string&lt;S...&gt;&gt;
{
	static char const c_str[];
};

template &lt;char... S&gt;
char const string&lt;S...&gt;::c_str[] = { S..., 0 };

template &lt;typename S1, typename S2&gt;
struct append
	: append&lt;typename S1::type, typename S2::type&gt;
{};

template &lt;char... S1, char... S2&gt;
struct append&lt;string&lt;S1...&gt;, string&lt;S2...&gt;&gt;
	: string&lt;S1..., S2...&gt;
{};

template &lt;unsigned I&gt;
struct to_string
	: std::conditional
	&lt;
		I &lt; 10,
		string&lt;I + '0'&gt;,
		append&lt;to_string&lt;I / 10&gt;, string&lt;I % 10 + '0'&gt;&gt;
	&gt;::type
{};

template &lt;typename A, typename B&gt;
struct less
	: bool_&lt;(A::value &lt; B::value)&gt;
{};

template &lt;typename I&gt;
struct to_string_if_prime
	: std::conditional
	&lt;
		is_prime&lt;I::value&gt;::value,
		append&lt;to_string&lt;I::value&gt;, string&lt;' '&gt;&gt;,
		string&lt;&gt;
	&gt;
{};

template &lt;unsigned N&gt;
struct primes_below
	: for_
	&lt;
		unsigned_&lt;0&gt;,
		bind2nd&lt;less, unsigned_&lt;N&gt;&gt;::template binder2nd,
		increment,
		to_string_if_prime,
		append,
		string&lt;&gt;
	&gt;
{};

int main()
{
	std::cout &lt;&lt; primes_below&lt;100&gt;::type::c_str &lt;&lt; '\n';
}
</code></pre>
<p><a href="http://ideone.com/tswvn" rel="nofollow">http://ideone.com/tswvn</a></p>
<p>Man möge mir das überschüssige Whitespace am Ende verzeihen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220067</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 05 Jun 2012 23:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme bei Tutorial (Programm zur Auflistung aller Primzahlen von 1 bis 100) on Wed, 06 Jun 2012 00:03:50 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/tswvn" rel="nofollow">http://ideone.com/tswvn</a>Man möge mir das überschüssige Whitespace am Ende verzeihen.</p>
</blockquote>
<p>Sehr schöne Buchlösung, verliert aber Stilpunkte wegen for_ <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>Jetzt noch bitte eine Variante, bei der die Tiefe der rekursiven Instantiierung beschränkt ist auf sagen wir 10.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2220070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2220070</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 06 Jun 2012 00:03:50 GMT</pubDate></item></channel></rss>