<?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[char nach char Konvertieren]]></title><description><![CDATA[<p>Wie kann man ein char nach char Konvertieren?</p>
<p>So funktionierte es nicht <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

int main()
{

char text = &quot;abc&quot;;
char speicher;

       cout&lt;&lt; text;
       speicher = text;

cout&lt;&lt;speicher;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/234060/char-nach-char-konvertieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 14:37:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/234060.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Feb 2009 14:47:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 14:47:36 GMT]]></title><description><![CDATA[<p>Wie kann man ein char nach char Konvertieren?</p>
<p>So funktionierte es nicht <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

int main()
{

char text = &quot;abc&quot;;
char speicher;

       cout&lt;&lt; text;
       speicher = text;

cout&lt;&lt;speicher;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1662579</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662579</guid><dc:creator><![CDATA[char]]></dc:creator><pubDate>Thu, 12 Feb 2009 14:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 14:59:29 GMT]]></title><description><![CDATA[<p>Mein Compiler sagt dazu:</p>
<pre><code>main.cpp: In function ‘int main()’:
main.cpp:8: error: invalid conversion from ‘const char*’ to ‘char’
</code></pre>
<p>Was bedeuted das? Naja, schauen wir mal in Zeile 8:</p>
<pre><code>char text = &quot;abc&quot;;
</code></pre>
<p>Leider ist &quot;abc&quot; vom Typ char* und nicht vom Typ char. Korrigiere das und dann sag mir, was du machen willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662587</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 12 Feb 2009 14:59:29 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:00:01 GMT]]></title><description><![CDATA[<p>So</p>
<pre><code class="language-cpp">char text = 'abc';
</code></pre>
<p>und nicht so</p>
<pre><code class="language-cpp">char text = &quot;abc&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1662588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662588</guid><dc:creator><![CDATA[EEK@work]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:00:01 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:02:31 GMT]]></title><description><![CDATA[<p>EEK@work schrieb:</p>
<blockquote>
<p>So</p>
<pre><code class="language-cpp">char text = 'abc';
</code></pre>
<p>und nicht so</p>
<pre><code class="language-cpp">char text = &quot;abc&quot;;
</code></pre>
</blockquote>
<p>Das geht nicht. 1 char ist 1 zeichen. Mehrfache gehen da nicht.<br />
Was du willst:</p>
<pre><code class="language-cpp">char* text = new char[strlen(&quot;abc&quot;)];
strcpy(text, &quot;abc&quot;);
// Irgendwas damit machen
delete char;

// oder:
char text[3] = { 'a', 'b', 'c' };
</code></pre>
<p>rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662592</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:02:31 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:07:43 GMT]]></title><description><![CDATA[<p>EEK@work schrieb:</p>
<blockquote>
<p>So</p>
<pre><code class="language-cpp">char text = 'abc';
</code></pre>
</blockquote>
<p>Nein, bestimmt nicht! Was soll denn rauskommen? Ausprobiert und text ist dann c. Mein Compiler sagt dazu:</p>
<pre><code>main.cpp:8: warning: overflow in implicit constant conversion
</code></pre>
<p>Und Overflow ist nie gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662594</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:07:43 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:05:53 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>EEK@work schrieb:</p>
<blockquote>
<p>So</p>
<pre><code class="language-cpp">char text = 'abc';
</code></pre>
<p>und nicht so</p>
<pre><code class="language-cpp">char text = &quot;abc&quot;;
</code></pre>
</blockquote>
<p>Das geht nicht. 1 char ist 1 zeichen. Mehrfache gehen da nicht.<br />
Was du willst:</p>
<pre><code class="language-cpp">char* text = new char[strlen(&quot;abc&quot;)];
strcpy(text, &quot;abc&quot;);
// Irgendwas damit machen
delete char;

// oder:
char text[3] = { 'a', 'b', 'c' };
</code></pre>
<p>rya.</p>
</blockquote>
<p>Ups, stimmt. Man sollte sich den Quellcode genau anschauen. Ich dachte er will nur ein Zeichen kopieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662597</guid><dc:creator><![CDATA[EEK@work]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:05:53 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:21:26 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Das geht nicht. 1 char ist 1 zeichen. Mehrfache gehen da nicht.<br />
Was du willst:</p>
<pre><code class="language-cpp">char* text = new char[strlen(&quot;abc&quot;)];
strcpy(text, &quot;abc&quot;);
// Irgendwas damit machen
delete char;

// oder:
char text[3] = { 'a', 'b', 'c' };
</code></pre>
<p>rya.</p>
</blockquote>
<p>Wenn dann wohl</p>
<pre><code class="language-cpp">delete [] text;
</code></pre>
<p>wenn ichs nicht falsch habe.</p>
<p>Plus, wieso den Speicher selber anfordern? Und vor allem, wieso nicht std::string?</p>
<p>Edit: Beim &quot;//oder:&quot; Teil fehlt übrigens auch die terminierende '\0'.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662599</guid><dc:creator><![CDATA[issen1]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:21:26 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:15:48 GMT]]></title><description><![CDATA[<p>Hiermit kann ich nicht so recht was anfangen ...</p>
<pre><code class="language-cpp">char* text = new char[strlen(&quot;abc&quot;)]; 
strcpy(text, &quot;abc&quot;); 
// Irgendwas damit machen 
delete char; 

// oder: 
char text[3] = { 'a', 'b', 'c' };
</code></pre>
<p>Ich hab jetzt so gelöst:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

int main()
{

char text[20] = {'a','b','c'};
char speicher[20];

        for (int i=0;i&lt;4;i++)
        {
        speicher[i] = text[i];
        }

        for (int j=0; j&lt;4;j++)
        {
        cout&lt;&lt;speicher[j];
        }
system(&quot;PAUSE&quot;);
}
</code></pre>
<p>Aber trotzdem würde mich interessiere was hier so passiert:</p>
<p>char* text = new char[strlen(&quot;abc&quot;)];<br />
strcpy(text, &quot;abc&quot;);<br />
delete char;</p>
<p>Kennt wer eine Seite wo man das nachlesen kann?<br />
Hab kp wo nach ich da jetzt googeln sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662606</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662606</guid><dc:creator><![CDATA[char]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:15:48 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:20:51 GMT]]></title><description><![CDATA[<p>Also dein Code ist eher suboptimal und geht mehr in Richtung C. Das koennte dir helfen, wenn du alles durchliest: <a href="http://www.cs.cf.ac.uk/Dave/C/" rel="nofollow">http://www.cs.cf.ac.uk/Dave/C/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662610</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:20:51 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:21:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">// hier wird Speicher für char angefordert und zwar in der Länge von &quot;abc&quot;. 
char* text = new char[strlen(&quot;abc&quot;)];

// Hier wird &quot;abc&quot; in diesen Speicher kopiert
strcpy(text, &quot;abc&quot;);

// Hier wird der Speicher an das OS zurückgegeben
delete [] text;
</code></pre>
<p>rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662612</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:21:46 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:28:28 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt; // Wozu inkludierst du fstream?
using namespace std;

int main()
{

char text[20] = {'a','b','c'}; // '\0' vergessen anzugeben
char speicher[20];

// falsch eingerückt *hust*
// außerdem viel zu kompliziert.
// wenn du C++ programmieren willst bitte auch STL inkl. std::string nutzen (siehe unten)

        for (int i=0;i&lt;4;i++)
        {
        speicher[i] = text[i];
        }

        for (int j=0; j&lt;4;j++)
        {
        cout&lt;&lt;speicher[j];
        }
system(&quot;PAUSE&quot;); // auch böse, benutz besser cin
}
</code></pre>
<p>Ich hätte es wahrscheinlich so gelöst:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
    std::string text = &quot;buuh&quot;;
    std::string speicher;

    speicher = text;
    std::cout &lt;&lt; speicher;

    std::cin.ignore();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1662618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662618</guid><dc:creator><![CDATA[issen1]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:28:28 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:28:29 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">// hier wird Speicher für char angefordert und zwar in der Länge von &quot;abc&quot;. 
char* text = new char[strlen(&quot;abc&quot;)];

// Hier wird &quot;abc&quot; in diesen Speicher kopiert
strcpy(text, &quot;abc&quot;);

// Hier wird der Speicher an das OS zurückgegeben
delete [] text;
</code></pre>
<p>rya.</p>
</blockquote>
<p>oO. -&gt; man strcpy:</p>
<pre><code>The  strcpy()  function  copies the string pointed to by src, including
the terminating null byte ('\0')
</code></pre>
<p>Du reservierst Platz fuer 3 chars und kopierst 4. Nein! Eine bessere alternative ist strncpy.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662621</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:34:36 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>oO. -&gt; man strcpy:</p>
<pre><code>The  strcpy()  function  copies the string pointed to by src, including
the terminating null byte ('\0')
</code></pre>
<p>Du reservierst Platz fuer 3 chars und kopierst 4. Nein! Eine bessere alternative ist strncpy.</p>
</blockquote>
<p>Kopiert strcpy nicht solange bis es ein '\0' entdeckt? Das wären noch ein paar Bytes mehr. Siehe dieses Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
	char text1[5] = {'h', 'a', 'l', 'l', 'o'};
	char* padding = &quot;buuh&quot;;
	char* addition = new char[20];

	strcpy(addition, text1);
	std::cout &lt;&lt; addition;

	delete [] addition;

	std::cin.ignore();
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1662626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662626</guid><dc:creator><![CDATA[issen1]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:34:36 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:35:06 GMT]]></title><description><![CDATA[<p>ahhh zu früh gefreut <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>
<p>Was ich nun genau machen will:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main(int argc, char* argv[])
{

char text = 65;
char speicher;

speicher = text;

cout &lt;&lt; hex &lt;&lt;speicher;

return 0;
}
</code></pre>
<p>Das funktioniert einwandfrei.</p>
<p>Was aber wenn ich anstatt char text = 'abc'; habe ?</p>
<p>Das muss doch auch irgendwie gehen oder nicht ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662627</guid><dc:creator><![CDATA[char]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:35:06 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:35:26 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Du reservierst Platz fuer 3 chars und kopierst 4. Nein! Eine bessere alternative ist strncpy.</p>
</blockquote>
<p>Flüchtigkeitsfehler, aber natürlich richtig :).<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662628</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:35:26 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:37:56 GMT]]></title><description><![CDATA[<p>So jetzt aber <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main(int argc, char* argv[])
{

char *text = &quot;abc&quot;;
char *speicher;

speicher = text;

cout &lt;&lt; hex &lt;&lt;speicher;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1662630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662630</guid><dc:creator><![CDATA[char]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:37:56 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:38:20 GMT]]></title><description><![CDATA[<p>@Char: Schau dir bitte nochmal die Grundlagen an bzw. fang an dir die Grundlagen anzuschauen. Kauf dir ein Buch oder lese dir ein Anfängertutorial durch. Eine mögliche Alternative zu deinem Code habe ich bereits in diesem Thread gepostet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662631</guid><dc:creator><![CDATA[issen1]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:42:31 GMT]]></title><description><![CDATA[<p>Jetzt geht das mit dem dummen hex ding nich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>Ich hab schon ein Tutorial durchgearbeitet aber mit der Zeit Vergess ich immer son paar Sachen <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/1662634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662634</guid><dc:creator><![CDATA[char]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:42:31 GMT</pubDate></item><item><title><![CDATA[Reply to char nach char Konvertieren on Thu, 12 Feb 2009 15:50:22 GMT]]></title><description><![CDATA[<p>char schrieb:</p>
<blockquote>
<p>Jetzt geht das mit dem dummen hex ding nich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
</blockquote>
<p>Das nennt sich Manipulator. Begrifflichkeiten sind auch wichtig beim Programmieren.</p>
<p>char schrieb:</p>
<blockquote>
<p>Ich hab schon ein Tutorial durchgearbeitet aber mit der Zeit Vergess ich immer son paar Sachen <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>
</blockquote>
<p>Was soll ich sagen...? Üben, üben, üben! <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="😉"
    /> Erst die praktische Anwendung lässt einen die vielen Dinge im Gedächtnis halten. Ein Riesen-Tutorial komplett durchzulesen, ohne zwischendurch immer wieder Sachen selbst auszuprobieren, bringt leider wenig. Da vergisst man wirklich die Hälfte...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1662639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1662639</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Thu, 12 Feb 2009 15:50:22 GMT</pubDate></item></channel></rss>