<?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[Funktionen zum Debuggen]]></title><description><![CDATA[<p>Servus,</p>
<p>ich las, es gibt in C++ keine ähnlichen Funktionen wie var_dump() in php oder toString() in Java? Wie macht ihr es dann, wenn ihr euch die Inhalte einer Variablen anzeigen lassen wollt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270253/funktionen-zum-debuggen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 08:10:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270253.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Jul 2010 23:59:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionen zum Debuggen on Thu, 08 Jul 2010 23:59:31 GMT]]></title><description><![CDATA[<p>Servus,</p>
<p>ich las, es gibt in C++ keine ähnlichen Funktionen wie var_dump() in php oder toString() in Java? Wie macht ihr es dann, wenn ihr euch die Inhalte einer Variablen anzeigen lassen wollt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923629</guid><dc:creator><![CDATA[Jay1980]]></dc:creator><pubDate>Thu, 08 Jul 2010 23:59:31 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 00:49:45 GMT]]></title><description><![CDATA[<p>Wir benutzen einen Debugger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923641</guid><dc:creator><![CDATA[audacia]]></dc:creator><pubDate>Fri, 09 Jul 2010 00:49:45 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 07:00:23 GMT]]></title><description><![CDATA[<p>... oder man nutzt die streams (und die passenden operator&lt;&lt;() &amp; operator&gt;&gt;()).<br />
Die können in C++ nämlich nicht nur mit strings umgehen, sondern prinzipiell mit allem.</p>
<pre><code class="language-cpp">string s = &quot;mein String&quot;;
int i = 2;
double d = 3.4;
char c = 'c';
myClass m ('f', d, 17);

// auf die Konsole
cout &lt;&lt; s &lt;&lt; i &lt;&lt; d &lt;&lt; c &lt;&lt; m;

// in ein File
ofstream logFile(&quot;myPG.log&quot;);
logfile &lt;&lt; s &lt;&lt; i &lt;&lt; d &lt;&lt; c &lt;&lt; m;

// in einen string
ostringstream ost;
ost &lt;&lt; s &lt;&lt; i &lt;&lt; d &lt;&lt; c &lt;&lt; m;
mach_was_mit_einem_string(ost.str());
</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>
<p>Gruß,</p>
<p>Simon2.</p>
<p>P.S.: OK für myClass muss man noch einen operator&lt;&lt;() selbst schreiben, aber das ist generisch und nahezu trivial - und auch nicht anders als javas toString() .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923675</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 09 Jul 2010 07:00:23 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 07:01:37 GMT]]></title><description><![CDATA[<p>Jay1980 schrieb:</p>
<blockquote>
<p>Servus,</p>
<p>ich las, es gibt in C++ keine ähnlichen Funktionen wie var_dump() in php oder toString() in Java? Wie macht ihr es dann, wenn ihr euch die Inhalte einer Variablen anzeigen lassen wollt?</p>
</blockquote>
<p>Wie schon mein Vorgänger geschrieben hat, benutzt man am besten einen Debugger. Das geht aber nicht immer. Dafür habe ich mir eine kleine Funktionsbibliothek geschrieben, mit der ich die Inhalte bestimmter Variablen in eine Log-Datei ausgeben kann. In die Logdatei schreibe ich dann auch noch Quelltextname uns Zeilennummer. Das ganze is so implementiert, daß es natürlich nur dann greift, wenn das Makro NDEBUG nicht gesetzt ist.</p>
<p>Das sieht dann beispielsweiose so aus:</p>
<pre><code class="language-cpp">doEnterFunction(&quot;MIDIdrumWindow::stopPlayMidi&quot;);
...
doLogValue( &quot;%d&quot;, i );
....
doShowLog();
</code></pre>
<p>Der dazugehörige Header sieht so aus:</p>
<pre><code class="language-cpp">#if !defined( NDEBUG ) || defined( _DEBUG )
void logValue( const char *fName, int lineNum, const char *var, const char *format, ... );

void startLog( const char *file, int line, const char *function );
void showLog( const char *file, int line );

void enableLog( void );
void disableLog( void );

#define doLogValue( fmt, val )	logValue( __FILE__, __LINE__, #val, fmt, val )
#define doLogPosition()			logValue( __FILE__, __LINE__, &quot;&quot;, &quot;&quot;, &quot;&quot; )

#define doStartLog() 			startLog( __FILE__, __LINE__, &quot;&quot; )
#define doEnterFunction( x )	startLog( __FILE__, __LINE__, x )
#define doShowLog()				showLog( __FILE__, __LINE__ )

#define doEnableLog()			enableLog()
#define doDisableLog()			disableLog()

#else
#define doLogValue( fmt, val )	/* nothing */
#define doLogPosition()			/* nothing */

#define doStartLog()			/* nothing */
#define doEnterFunction( x )	/* nothing */
#define doShowLog()				/* nothing */

#define doEnableLog()			/* nothing */
#define doDisableLog()			/* nothing */

#endif
</code></pre>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923678</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Fri, 09 Jul 2010 07:01:37 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 07:02:23 GMT]]></title><description><![CDATA[<p>Oder man nutzt Makros:</p>
<pre><code class="language-cpp">#ifdef DEBUG
#define DEBUG_OUT(x) std::cout &lt;&lt; #x##&quot;=&quot; &lt;&lt; x &lt;&lt; std::endl;
#else
#define DEBUG_OUT(x) ;
#endif

//...

int x = 5;

DEBUG_OUT(x)
</code></pre>
<p>kann sein das ich mich mit dem ## vertue, sonst halt &lt;&lt;. <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/1923679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923679</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Fri, 09 Jul 2010 07:02:23 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 07:04:56 GMT]]></title><description><![CDATA[<p>Oder wir führen nach 'Alt Väter Sitte' zum Testen eine Protokolldatei mit. Hierin trägt man wichtige Schritte und Variable des Programmablaufes ein und kann sich die in Ruhe in einer Datei ansehen. Was nicht mehr gebraucht wird, wird auskommentiert und kann bei Bedarf (Wartung) jederzeit reaktiviert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923683</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Fri, 09 Jul 2010 07:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 09:05:54 GMT]]></title><description><![CDATA[<p>Das ist aber auch kein &quot;C++-Spezifikum&quot;, sondern müsste man in Java doch auch so machen, oder?</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923742</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 09 Jul 2010 09:05:54 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Fri, 09 Jul 2010 12:23:56 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Das ist aber auch kein &quot;C++-Spezifikum&quot;, sondern müsste man in Java doch auch so machen, oder?</p>
</blockquote>
<p>Klar, das ist kein 'C++-Spezifikum', weil man das überall effizient machen kann. Gehört jetzt aber in die Rubrik Programmierstil oder wäre eine der möglichen Antworten auf die Frage 'Wie mache ich mir das Leben als Programmierer möglichst einfach und vermeide verdeckte Fehler?' :p</p>
<p>C++-spezifisch ist jedoch, dafür wie vorgeschlagen streams einzusetzen - egal ob für Bildschirm oder Datei. Man spart sich dann das Nachdenken über Datentypen.</p>
<p>Der Fragesteller hat nach 'Funktionen zum Debuggen' gefragt. So etwas gibt es in C und C++ nicht und braucht es nicht zu geben. Man schmeisst einen Debugger an oder verwendet einen der anderen Vorschläge.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1923785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1923785</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Fri, 09 Jul 2010 12:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen zum Debuggen on Sat, 10 Jul 2010 20:51:03 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>...<br />
Der Fragesteller hat nach 'Funktionen zum Debuggen' gefragt. ...</p>
</blockquote>
<p>Ich hatte die Frage anders verstanden. &quot;Wie kann ich in C++ das machen, was ich in Java &lt;so-und-so&gt; mache?&quot;<br />
Ist aber auch egal - ich denke, für den Fragesteller ist eine Menge herausgekommen, was ihm weiterhilft.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1924426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1924426</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Sat, 10 Jul 2010 20:51:03 GMT</pubDate></item></channel></rss>