<?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[Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht?]]></title><description><![CDATA[<p>Das Programm soll die eingegebenen char's wieder ausgeben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;

using namespace std;

int main()
{
	char* a = new char[];
	cin &gt;&gt; a;
	for(unsigned int i = 0;i &lt; sizeof(a)-1; ++i)
	{
		cout &lt;&lt; a[i];
		Sleep(50);
	}
        delete[] a;
	system(&quot;pause&quot;);
}
</code></pre>
<p><strong>HIER GING ES NOCH:</strong></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;

using namespace std;

int main()
{
	char a[] = &quot;hallo welt!\n&quot;;
	for(unsigned int i = 0;i &lt; sizeof(a)-1; ++i)
	{
		cout &lt;&lt; a[i];
		Sleep(50);
	}
	system(&quot;pause&quot;);
}
</code></pre>
<p>ACH STIMMT JA! EIN ZEIGER HAT NUR 4 BYTES IN EINEM 32BIT SYSTEM. WIE KRIEGE ICH DIE LÄNGE DES ARRAY'S IN DIESEM FALL DENN SONST RAUS?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/247827/warum-funktioniert-hier-das-quot-sizeof-quot-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 11:59:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/247827.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Aug 2009 11:22:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:29:36 GMT]]></title><description><![CDATA[<p>Das Programm soll die eingegebenen char's wieder ausgeben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;

using namespace std;

int main()
{
	char* a = new char[];
	cin &gt;&gt; a;
	for(unsigned int i = 0;i &lt; sizeof(a)-1; ++i)
	{
		cout &lt;&lt; a[i];
		Sleep(50);
	}
        delete[] a;
	system(&quot;pause&quot;);
}
</code></pre>
<p><strong>HIER GING ES NOCH:</strong></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;

using namespace std;

int main()
{
	char a[] = &quot;hallo welt!\n&quot;;
	for(unsigned int i = 0;i &lt; sizeof(a)-1; ++i)
	{
		cout &lt;&lt; a[i];
		Sleep(50);
	}
	system(&quot;pause&quot;);
}
</code></pre>
<p>ACH STIMMT JA! EIN ZEIGER HAT NUR 4 BYTES IN EINEM 32BIT SYSTEM. WIE KRIEGE ICH DIE LÄNGE DES ARRAY'S IN DIESEM FALL DENN SONST RAUS?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761654</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:29:36 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:39:29 GMT]]></title><description><![CDATA[<p>skullyan schrieb:</p>
<blockquote>
<p>ACH STIMMT JA! EIN ZEIGER HAT NUR 4 BYTES IN EINEM 32BIT SYSTEM. WIE KRIEGE ICH DIE LÄNGE DES ARRAY'S IN DIESEM FALL DENN SONST RAUS?</p>
</blockquote>
<p>Das ist aber kein Grund gleich zu schreien.<br />
Die Länge eines Strings erhältst du mit der Funktion <code>strlen</code> .<br />
Dein Code funktioniert allerdings so nicht, weil</p>
<pre><code class="language-cpp">char* a = new char[];
</code></pre>
<p>kein gültiger C++-Code ist.<br />
In C++ verwendet man überdies besser <code>std::string</code> anstelle der rohen char-Arrays.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761662</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:39:29 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:45:11 GMT]]></title><description><![CDATA[<p>Registrierter Troll schrieb:</p>
<blockquote>
<p>skullyan schrieb:</p>
<blockquote>
<p>ACH STIMMT JA! EIN ZEIGER HAT NUR 4 BYTES IN EINEM 32BIT SYSTEM. WIE KRIEGE ICH DIE LÄNGE DES ARRAY'S IN DIESEM FALL DENN SONST RAUS?</p>
</blockquote>
<p>Das ist aber kein Grund gleich zu schreien.<br />
Die Länge eines Strings erhältst du mit der Funktion <code>strlen</code> .<br />
Dein Code funktioniert allerdings so nicht, weil</p>
<pre><code class="language-cpp">char* a = new char[];
</code></pre>
<p>kein gültiger C++-Code ist.<br />
In C++ verwendet man überdies besser <code>std::string</code> anstelle der rohen char-Arrays.</p>
</blockquote>
<p>Aha, und wie sähe da die Lösung in Codeform aus? Ich kann es mir zur Zeit irgendwie nicht so recht vorstellen...<br />
<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/1761669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761669</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:45:11 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:50:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
    string a;
    getline( cin, a );
    cout &lt;&lt; a;
    system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1761671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761671</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:50:53 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:52:13 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
    string a;
    getline( cin, a );
    cout &lt;&lt; a;
    system(&quot;pause&quot;);
}
</code></pre>
</blockquote>
<p>Klappt nicht:</p>
<pre><code>error C2040: 'a': 'std::string' unterscheidet sich von 'char *' in Bezug auf die Anzahl vorgenommener Dereferenzierungen
error C2088: '&lt;&lt;': Ungültig für class
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1761672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761672</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:52:13 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:52:20 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
	string a;
	cin &gt;&gt; a;
	for(string::const_iterator i = a.begin(); i != a.end(); ++i)
	{
		cout &lt;&lt; *i;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1761673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761673</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:52:20 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 11:57:45 GMT]]></title><description><![CDATA[<p>skullyan schrieb:</p>
<blockquote>
<p>David_pb schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
    string a;
    getline( cin, a );
    cout &lt;&lt; a;
    system(&quot;pause&quot;);
}
</code></pre>
</blockquote>
<p>Klappt nicht:</p>
<pre><code>error C2040: 'a': 'std::string' unterscheidet sich von 'char *' in Bezug auf die Anzahl vorgenommener Dereferenzierungen
error C2088: '&lt;&lt;': Ungültig für class
</code></pre>
</blockquote>
<p>Klappt schon... Nur kannst du nicht davon ausgehen das merkwürdig zusammengefügter Code immer noch funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761679</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sun, 16 Aug 2009 11:57:45 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 12:10:56 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<p>skullyan schrieb:</p>
<blockquote>
<p>David_pb schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
    string a;
    getline( cin, a );
    cout &lt;&lt; a;
    system(&quot;pause&quot;);
}
</code></pre>
</blockquote>
<p>Klappt nicht:</p>
<pre><code>error C2040: 'a': 'std::string' unterscheidet sich von 'char *' in Bezug auf die Anzahl vorgenommener Dereferenzierungen
error C2088: '&lt;&lt;': Ungültig für class
</code></pre>
</blockquote>
<p>Klappt schon... Nur kannst du nicht davon ausgehen das merkwürdig zusammengefügter Code immer noch funktioniert.</p>
</blockquote>
<p>Ja, mein Compiler hat mir da einen Streich gespielt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761685</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sun, 16 Aug 2009 12:10:56 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 12:13:41 GMT]]></title><description><![CDATA[<p>Registrierter Troll schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

int main()
{
	string a;
	cin &gt;&gt; a;
	for(string::const_iterator i = a.begin(); i != a.end(); ++i)
	{
		cout &lt;&lt; *i;
	}
}
</code></pre>
</blockquote>
<p>Diese Lösung gefällt mir, allerdings brauche ich auch eine Lösung für <code>getline()</code> . Wenn ich einen Satz eingebe, wird nur das erste Wort ausgegeben. Also die Ausgabe erfolgt nur bis zum ersten Leerzeichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761686</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sun, 16 Aug 2009 12:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 12:29:12 GMT]]></title><description><![CDATA[<p>skullyan schrieb:</p>
<blockquote>
<p>Diese Lösung gefällt mir, allerdings brauche ich auch eine Lösung für <code>getline()</code> .</p>
</blockquote>
<p>Kannst du nicht selber ein wenig kombinieren, muss dir alles wortwörtlich vorgesetzt werden?</p>
<p>Wenn du dich ein wenig bemühst, findest du bestimmt eine gute Erklärung auf <a href="http://www.cplusplus.com" rel="nofollow">www.cplusplus.com</a>. Zusammen mit den Codeteilen hier sollte es kein Problem mehr sein, das umzusetzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761697</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761697</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 16 Aug 2009 12:29:12 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 12:42:00 GMT]]></title><description><![CDATA[<blockquote>
<p>char* a = new char[];<br />
cin &gt;&gt; a;</p>
</blockquote>
<p>Also ich bin mir nicht sicher, aber das kann doch auch nicht funktionieren,<br />
weil a kein dynamisches Array ist, dass sich automatisch vergrößert, oder?<br />
Wenn Du die Klammern leer lässt, dann passt sich das Array immer dem an, was du direkt danach zuweist?!</p>
<p>Irre ich mich oder habe ich recht?</p>
<p>lg, freakC++</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761702</guid><dc:creator><![CDATA[freakC++]]></dc:creator><pubDate>Sun, 16 Aug 2009 12:42:00 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 14:16:49 GMT]]></title><description><![CDATA[<p>freakC++ schrieb:</p>
<blockquote>
<blockquote>
<p>char* a = new char[];<br />
cin &gt;&gt; a;</p>
</blockquote>
<p>Also ich bin mir nicht sicher, aber das kann doch auch nicht funktionieren,<br />
weil a kein dynamisches Array ist, dass sich automatisch vergrößert, oder?<br />
Wenn Du die Klammern leer lässt, dann passt sich das Array immer dem an, was du direkt danach zuweist?!</p>
<p>Irre ich mich oder habe ich recht?</p>
<p>lg, freakC++</p>
</blockquote>
<p>Wie Registrierter Troll schon sagte, der Code ist so nicht in Ordnung.<br />
Wenn du mit dem zweiten Teil das hier meinst:</p>
<pre><code class="language-cpp">char a[] = &quot;Hallo&quot;; // a hat danach die Länge 6
</code></pre>
<p>Dann liegst du damit auch richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761748</guid><dc:creator><![CDATA[blub* 0]]></dc:creator><pubDate>Sun, 16 Aug 2009 14:16:49 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 14:38:28 GMT]]></title><description><![CDATA[<p>Registrierter Troll schrieb:</p>
<blockquote>
<p>Das ist aber kein Grund gleich zu schreien.</p>
</blockquote>
<p>Schreien tut man mit den Stimmbändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761758</guid><dc:creator><![CDATA[Ruhiger Mensch]]></dc:creator><pubDate>Sun, 16 Aug 2009 14:38:28 GMT</pubDate></item><item><title><![CDATA[Reply to Warum funktioniert hier das &amp;quot;sizeof&amp;quot; nicht? on Sun, 16 Aug 2009 18:00:21 GMT]]></title><description><![CDATA[<p>Ruhiger Mensch schrieb:</p>
<blockquote>
<p>Registrierter Troll schrieb:</p>
<blockquote>
<p>Das ist aber kein Grund gleich zu schreien.</p>
</blockquote>
<p>Schreien tut man mit den Stimmbändern.</p>
</blockquote>
<p>Sag das nicht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1761877</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1761877</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 16 Aug 2009 18:00:21 GMT</pubDate></item></channel></rss>