<?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[[Erledigt] Umgang mit char arrays]]></title><description><![CDATA[<p>Guten Tag,<br />
vorweg: ich bin ein absoluter C++ Anfänger.<br />
Also ich habe das Problem, dass ich es nicht schaffe eine Zeichenkette in ein char[] Array zu schreiben. Hier einfach mal mein Code:</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

class Fach {
	public:
		Fach() {
			this-&gt;name = &quot;Fach&quot;;
			this-&gt;note = -1.0;
		}

		Fach(char* name, double note) {
			this-&gt;name = name;
			this-&gt;note = note;
		}

		char* getName() {
			return this-&gt;name;
		}

		double getNote() {
			return this-&gt;note;
		}

	private:
		char name[];
		double note;
};

int main() {

	return 0;
}
</code></pre>
<p>Das Problem betrifft Zeile 8.</p>
<p>Vielleicht könnt ihr mir da helfen und mir erklären wie ich damit umzugehen habe.</p>
<p>Grüße Creylon</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335429/erledigt-umgang-mit-char-arrays</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 15:28:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335429.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 20 Nov 2015 13:29:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:44:23 GMT]]></title><description><![CDATA[<p>Guten Tag,<br />
vorweg: ich bin ein absoluter C++ Anfänger.<br />
Also ich habe das Problem, dass ich es nicht schaffe eine Zeichenkette in ein char[] Array zu schreiben. Hier einfach mal mein Code:</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

class Fach {
	public:
		Fach() {
			this-&gt;name = &quot;Fach&quot;;
			this-&gt;note = -1.0;
		}

		Fach(char* name, double note) {
			this-&gt;name = name;
			this-&gt;note = note;
		}

		char* getName() {
			return this-&gt;name;
		}

		double getNote() {
			return this-&gt;note;
		}

	private:
		char name[];
		double note;
};

int main() {

	return 0;
}
</code></pre>
<p>Das Problem betrifft Zeile 8.</p>
<p>Vielleicht könnt ihr mir da helfen und mir erklären wie ich damit umzugehen habe.</p>
<p>Grüße Creylon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476193</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476193</guid><dc:creator><![CDATA[Creylon]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:44:23 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 13:34:12 GMT]]></title><description><![CDATA[<p>Benutze std::string statt char-Arrays. Die funktionieren dann auch ungefähr so, wie du es erwartest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476195</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 20 Nov 2015 13:34:12 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 13:43:53 GMT]]></title><description><![CDATA[<p>Gibt es keine Möglichkeit das mit char zu lösen? Ich würde meinen Code gerne einheitlich gestalten und da manche Funktionen nur mit char Arrays funktionieren, würde ich gerne alles mit char Arrays umsetzen. Zumal mein Dozent auch nur damit arbeitet.<br />
Des Weiteren wäre es dann einfacher für mich den double den ich dort habe in ein char array umzuwandeln, weil ich für die Klasse noch eine Methode brauche die mir die Daten in Form einer Zeichenkette zurückgibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476198</guid><dc:creator><![CDATA[Creylon]]></dc:creator><pubDate>Fri, 20 Nov 2015 13:43:53 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 13:53:25 GMT]]></title><description><![CDATA[<p>Creylon schrieb:</p>
<blockquote>
<p>Ich würde meinen Code gerne einheitlich gestalten</p>
</blockquote>
<p>Sollst du ja auch, mit <strong>std::string</strong></p>
<p>Creylon schrieb:</p>
<blockquote>
<p>da manche Funktionen nur mit char Arrays funktionieren, würde ich gerne alles mit char Arrays umsetzen.</p>
</blockquote>
<p>siehe oben</p>
<p>Creylon schrieb:</p>
<blockquote>
<p>Zumal mein Dozent auch nur damit arbeitet.</p>
</blockquote>
<p>Wenn er das wirklich tut: herzliches Beileid</p>
<p>Creylon schrieb:</p>
<blockquote>
<p>Gibt es keine Möglichkeit das mit char zu lösen?</p>
</blockquote>
<p>Klar gibt es die (das ist die, mit der dein Programm dann dauernd wegen irgendwelcher merkwürdigen Fehler abstürzt):<br />
Du musst für das Array eine feste Größe vorgeben, und dann den übergebenen String dort hinein kopieren (siehe std::copy, std::strcpy).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476201</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 20 Nov 2015 13:53:25 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 13:57:51 GMT]]></title><description><![CDATA[<p>Creylon schrieb:</p>
<blockquote>
<p>da manche Funktionen nur mit char Arrays funktionieren</p>
</blockquote>
<p>Hallo,</p>
<p>die kannst du dann immernoch mit string::c_str() aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476202</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Fri, 20 Nov 2015 13:57:51 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:29:34 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Creylon schrieb:</p>
<blockquote>
<p>Zumal mein Dozent auch nur damit arbeitet.</p>
</blockquote>
<p>Wenn er das wirklich tut: herzliches Beileid</p>
</blockquote>
<p>Ist das in anderen Fächern eigentlich auch so schlimm? Gibt es zum Beispiel Mathematik-Dozenten, die auf römischen Ziffern bestehen oder Physiker, die Längen unbedingt in &quot;Ellen&quot; oder so messen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476209</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:29:34 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:31:24 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Sollst du ja auch, mit <strong>std::string</strong></p>
</blockquote>
<p>Alles klar, mit string funktioniert es jetzt. Nun will ich aber sprintf nutzen, um eine formatierte Zeichenkette in eine String Variable zu speichern.</p>
<p>sprintf nimmt aber nur ein char Array.</p>
<p>Jockelx schrieb:</p>
<blockquote>
<p>die kannst du dann immernoch mit string::c_str() aufrufen.</p>
</blockquote>
<p>Diese Funktion scheint mir ein const char Array zu liefern, weshalb</p>
<pre><code>Fach fach;

	string s;

	sprintf(s.c_str(), &quot;%s\t%f&quot;, fach.getName(), fach.getNote());
</code></pre>
<p>nicht funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476210</guid><dc:creator><![CDATA[Creylon]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:31:24 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:33:38 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Ist das in anderen Fächern eigentlich auch so schlimm? Gibt es zum Beispiel Mathematik-Dozenten, die auf römischen Ziffern bestehen oder Physiker, die Längen unbedingt in &quot;Ellen&quot; oder so messen?</p>
</blockquote>
<p>Keine Ahnung. Letztes Semester hab ich etliche Punkte abgezogen bekommen wegen solch kleinkackerigen Zeugs. Mein Dozent ist ein alter Russe. Keine Ahnung ob das was damit zu tun hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2476211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476211</guid><dc:creator><![CDATA[Creylon]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:33:38 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:39:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;sstream&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

int main()
{
        std::stringstream ss;
        ss &lt;&lt; &quot;Hallo&quot; &lt;&lt; &quot;\t&quot; &lt;&lt; 32.4f;
        std::string s = ss.str();
        std::cout &lt;&lt; s &lt;&lt; &quot;\n&quot;;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2476213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476213</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:39:59 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Umgang mit char arrays on Fri, 20 Nov 2015 14:43:41 GMT]]></title><description><![CDATA[<p>@manni66 Das ist es. Dankeschön für die Hilfe! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2476215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2476215</guid><dc:creator><![CDATA[Creylon]]></dc:creator><pubDate>Fri, 20 Nov 2015 14:43:41 GMT</pubDate></item></channel></rss>