<?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[Quellcode wiedergeben]]></title><description><![CDATA[<p>Ich hab da mal eine Frage:</p>
<p>Wenn man eine Kopie des eigenen Quellcodes auf dem Bildschirm ausgeben will, ohne auf eine Datei zuzugreifen, kann man das mit irgendeiner Preprozessor-Direktive machen? Ist da irgendwo der Quellcode der aktuellen Zeile gespeichert?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275698/quellcode-wiedergeben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 19:01:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275698.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Oct 2010 14:57:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Quellcode wiedergeben on Tue, 19 Oct 2010 14:57:58 GMT]]></title><description><![CDATA[<p>Ich hab da mal eine Frage:</p>
<p>Wenn man eine Kopie des eigenen Quellcodes auf dem Bildschirm ausgeben will, ohne auf eine Datei zuzugreifen, kann man das mit irgendeiner Preprozessor-Direktive machen? Ist da irgendwo der Quellcode der aktuellen Zeile gespeichert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967577</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967577</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Tue, 19 Oct 2010 14:57:58 GMT</pubDate></item><item><title><![CDATA[Reply to Quellcode wiedergeben on Tue, 19 Oct 2010 15:10:26 GMT]]></title><description><![CDATA[<p>Nein, für dein Quine musst du schon trickreicher programmieren (außer du verwendest <a href="http://de.wikipedia.org/wiki/HQ9%2B" rel="nofollow">HQ9+</a> als Sprache <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="🤡"
    /> ). Die übliche Vorgehensweise ist, dass du eine clevere Funktion bastelst, die deinen Quelltext durch &quot;Berechnung&quot; (üblicherweise Stringmanipulationen) als Ergebnis hat und das Funktionsergebnis dann ausgibst.</p>
<p>edit: Hier ein Beispiel aus Wikipedia:</p>
<pre><code class="language-cpp">char*f=&quot;char*f=%c%s%c;main() {printf(f,34,f,34,10);}%c&quot;;main() {printf(f,34,f,34,10);}
</code></pre>
<p>Dieser Code nutzt aus, dass die Funktion printf aus einfachen Argumenten eine komplexe Ausgabe machen kann. Man sollte dazu noch wissen, dass 34 in ASCII für Anführungsstriche steht, dieses Beispiel funktioniert folglich nicht auf extrem exotische Maschinen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967581</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 19 Oct 2010 15:10:26 GMT</pubDate></item><item><title><![CDATA[Reply to Quellcode wiedergeben on Tue, 19 Oct 2010 15:24:39 GMT]]></title><description><![CDATA[<p>Also mein Buch beantwortet die Frage so:</p>
<pre><code class="language-cpp">/* dieses Programm listet sich selbst */
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;
char AS = 34;         // Anführungsstriche
char BS = 92;         // Backslash
char NZ = 10;         // neue Zeile
void c(const string&amp; t) {
  cout &lt;&lt; t &lt;&lt; AS;
  unsigned int i = 0;
  while (i &lt; t.length()) {
     if (t[i] == NZ) cout &lt;&lt; BS &lt;&lt; 'n'&lt;&lt;AS&lt;&lt; t[i] &lt;&lt; AS;
     else cout &lt;&lt; t[i];
     ++i;
  }
  cout&lt;&lt;AS&lt;&lt;')'&lt;&lt;';'&lt;&lt;'c'&lt;&lt;'('&lt;&lt;'s'&lt;&lt;')'&lt;&lt;';'&lt;&lt;'}'&lt;&lt;NZ;
}
int main(){ string s(&quot;/* dieses Programm listet sich selbst */\n&quot;
&quot;#include &lt;string&gt;\n&quot;
&quot;#include &lt;iostream&gt;\n&quot;
&quot;using namespace std;\n&quot;
&quot;char AS = 34;         // Anführungsstriche\n&quot;
&quot;char BS = 92;         // Backslash\n&quot;
&quot;char NZ = 10;         // neue Zeile\n&quot;
&quot;void c(const string&amp; t) {\n&quot;
&quot;  cout &lt;&lt; t &lt;&lt; AS;\n&quot;
&quot;  unsigned int i = 0;\n&quot;
&quot;  while (i &lt; t.length()) {\n&quot;
&quot;     if (t[i] == NZ) cout &lt;&lt; BS &lt;&lt; 'n'&lt;&lt;AS&lt;&lt; t[i] &lt;&lt; AS;\n&quot;
&quot;     else cout &lt;&lt; t[i];\n&quot;
&quot;     ++i;\n&quot;
&quot;  }\n&quot;
&quot;  cout&lt;&lt;AS&lt;&lt;')'&lt;&lt;';'&lt;&lt;'c'&lt;&lt;'('&lt;&lt;'s'&lt;&lt;')'&lt;&lt;';'&lt;&lt;'}'&lt;&lt;NZ;\n&quot;
&quot;}\n&quot;
&quot;int main(){ string s(&quot;);c(s);}
</code></pre>
<p>Wenn ich das jetzt richtig sehe schreibt er das programm einfach nur in einen String oder was? Ich seh da auf den ersten Blick nicht wirklich was kompliziertes drin..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967591</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Tue, 19 Oct 2010 15:24:39 GMT</pubDate></item><item><title><![CDATA[Reply to Quellcode wiedergeben on Tue, 19 Oct 2010 15:34:21 GMT]]></title><description><![CDATA[<p>Du vergisst, dass der String, der das Programm enthalten soll, Teil des Programms ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967594</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Tue, 19 Oct 2010 15:34:21 GMT</pubDate></item></channel></rss>