<?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[Buffer ist zu klein troz dynamischem anlegen]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich versuche mich zur Zeit an einigen Aufgaben in C++ um das Buch welches ich lese an weiteren sachen an zu wenden um es besser zu vrstehen. Momentan bin ich bei Konstruktoren (KopierK. 7 KonvertierK) und dem Dynamischn nlegen von Speicher<br />
Mein folgendes Problem ist das ich eine Fehlermeldung bekomme mit &quot; Buffer is to low&quot; obwohl ich bei strcpy_s doch die Größe mit strlen() ermittel. Leider bekomme ich keine weiteren Meldungen und beim Debuggen fehlt mir die erfahrung um den Fehler zu ermitteln.</p>
<p>Daher wollte ich euch um Rat fragen, was ich momentan falsch mache. Eigendlich komme ich aus der C Richtung und C++ ist noch nicht ganz so mein Freund <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>Ausschnitt Kunde.hpp</p>
<pre><code>class Kunde{
	char *name;
	char *ort;
	int alter;
	double umsatz;
	int transaktion;
	int id;
	static int anzahl;
public:
	Kunde(const char *name=&quot;Kein Name&quot;, const char *ort=&quot;Kein Ort&quot;, const int alter=0);
	Kunde(const Kunde &amp;src);
	~Kunde();

	void kaufe(double u);
	static int getAnzahl();
	void print();

};
</code></pre>
<p>Ausschnitt Kunde.cpp</p>
<pre><code>#include &quot;Kunde.hpp&quot;
#include &lt;iostream&gt;
#include &lt;cstring&gt;

#define use_CRT_SECURE_NO_WARNINGS
using namespace std;

int Kunde::anzahl = 0;

Kunde::Kunde(const char *name, const char *ort, const int alter){
	this-&gt;name = new char[strlen(name) + 1];
	strcpy_s(this-&gt;name,strlen(name), name);
	this-&gt;ort = new char[strlen(ort) + 1];
	strcpy_s(this-&gt;ort, strlen(ort), ort );
	this-&gt;alter = alter;
	this-&gt;umsatz = 0;
	this-&gt;transaktion = 0;
	this-&gt;id = ++Kunde::anzahl;
}

Kunde::Kunde(const Kunde &amp;src){
	this-&gt;name = new char[strlen(src.name) + 1];
	strcpy_s(this-&gt;name, strlen(src.name), src.name );
	this-&gt;ort = new char[strlen(src.ort) + 1];
	strcpy_s(this-&gt;ort, strlen(src.ort), src.ort );
	this-&gt;alter = src.alter;
	this-&gt;umsatz = 0;
	this-&gt;transaktion = 0;
	this-&gt;id = ++Kunde::anzahl;
}

Kunde::~Kunde(){
	delete name;
	delete ort;
}

void Kunde::kaufe(double umsatz){
	this-&gt;umsatz += umsatz;
	this-&gt;transaktion;
}

int Kunde::getAnzahl(){
	return Kunde::anzahl;
}

void Kunde::print(){
	cout &lt;&lt; &quot;Kunde &quot; &lt;&lt; name &lt;&lt; &quot; aus &quot; &lt;&lt; ort
		&lt;&lt; &quot; (ID = &quot; &lt;&lt; id &lt;&lt; &quot;, &quot; &lt;&lt; alter &lt;&lt; &quot;Jahre) hatte &quot;
		&lt;&lt; transaktion &lt;&lt; &quot; Transaktion(en) und &quot; &lt;&lt; umsatz &lt;&lt; &quot; Euro Umsatz.&quot; &lt;&lt; endl;
}
</code></pre>
<p>Ausschnitt main.cpp</p>
<pre><code>#include &quot;kunde.hpp&quot;
#include &lt;iostream&gt;
using namespace std;
int main() {
	Kunde a(&quot;Kunde 1&quot;);
	Kunde meiera(&quot;Meier&quot;, &quot;Esslingen&quot;, 28);
	a.print();
	meiera.print();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/330229/buffer-ist-zu-klein-troz-dynamischem-anlegen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 11:54:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/330229.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Dec 2014 13:12:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 13:12:57 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich versuche mich zur Zeit an einigen Aufgaben in C++ um das Buch welches ich lese an weiteren sachen an zu wenden um es besser zu vrstehen. Momentan bin ich bei Konstruktoren (KopierK. 7 KonvertierK) und dem Dynamischn nlegen von Speicher<br />
Mein folgendes Problem ist das ich eine Fehlermeldung bekomme mit &quot; Buffer is to low&quot; obwohl ich bei strcpy_s doch die Größe mit strlen() ermittel. Leider bekomme ich keine weiteren Meldungen und beim Debuggen fehlt mir die erfahrung um den Fehler zu ermitteln.</p>
<p>Daher wollte ich euch um Rat fragen, was ich momentan falsch mache. Eigendlich komme ich aus der C Richtung und C++ ist noch nicht ganz so mein Freund <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>Ausschnitt Kunde.hpp</p>
<pre><code>class Kunde{
	char *name;
	char *ort;
	int alter;
	double umsatz;
	int transaktion;
	int id;
	static int anzahl;
public:
	Kunde(const char *name=&quot;Kein Name&quot;, const char *ort=&quot;Kein Ort&quot;, const int alter=0);
	Kunde(const Kunde &amp;src);
	~Kunde();

	void kaufe(double u);
	static int getAnzahl();
	void print();

};
</code></pre>
<p>Ausschnitt Kunde.cpp</p>
<pre><code>#include &quot;Kunde.hpp&quot;
#include &lt;iostream&gt;
#include &lt;cstring&gt;

#define use_CRT_SECURE_NO_WARNINGS
using namespace std;

int Kunde::anzahl = 0;

Kunde::Kunde(const char *name, const char *ort, const int alter){
	this-&gt;name = new char[strlen(name) + 1];
	strcpy_s(this-&gt;name,strlen(name), name);
	this-&gt;ort = new char[strlen(ort) + 1];
	strcpy_s(this-&gt;ort, strlen(ort), ort );
	this-&gt;alter = alter;
	this-&gt;umsatz = 0;
	this-&gt;transaktion = 0;
	this-&gt;id = ++Kunde::anzahl;
}

Kunde::Kunde(const Kunde &amp;src){
	this-&gt;name = new char[strlen(src.name) + 1];
	strcpy_s(this-&gt;name, strlen(src.name), src.name );
	this-&gt;ort = new char[strlen(src.ort) + 1];
	strcpy_s(this-&gt;ort, strlen(src.ort), src.ort );
	this-&gt;alter = src.alter;
	this-&gt;umsatz = 0;
	this-&gt;transaktion = 0;
	this-&gt;id = ++Kunde::anzahl;
}

Kunde::~Kunde(){
	delete name;
	delete ort;
}

void Kunde::kaufe(double umsatz){
	this-&gt;umsatz += umsatz;
	this-&gt;transaktion;
}

int Kunde::getAnzahl(){
	return Kunde::anzahl;
}

void Kunde::print(){
	cout &lt;&lt; &quot;Kunde &quot; &lt;&lt; name &lt;&lt; &quot; aus &quot; &lt;&lt; ort
		&lt;&lt; &quot; (ID = &quot; &lt;&lt; id &lt;&lt; &quot;, &quot; &lt;&lt; alter &lt;&lt; &quot;Jahre) hatte &quot;
		&lt;&lt; transaktion &lt;&lt; &quot; Transaktion(en) und &quot; &lt;&lt; umsatz &lt;&lt; &quot; Euro Umsatz.&quot; &lt;&lt; endl;
}
</code></pre>
<p>Ausschnitt main.cpp</p>
<pre><code>#include &quot;kunde.hpp&quot;
#include &lt;iostream&gt;
using namespace std;
int main() {
	Kunde a(&quot;Kunde 1&quot;);
	Kunde meiera(&quot;Meier&quot;, &quot;Esslingen&quot;, 28);
	a.print();
	meiera.print();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2435143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435143</guid><dc:creator><![CDATA[Kohlerer]]></dc:creator><pubDate>Mon, 29 Dec 2014 13:12:57 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 13:19:15 GMT]]></title><description><![CDATA[<p>Code nicht gelesen. Nimm <code>std::string</code> !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435144</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Mon, 29 Dec 2014 13:19:15 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 13:21:18 GMT]]></title><description><![CDATA[<p>strlen(x) &lt; (strlen(x) + 1)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435146</guid><dc:creator><![CDATA[Schauder]]></dc:creator><pubDate>Mon, 29 Dec 2014 13:21:18 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 13:31:05 GMT]]></title><description><![CDATA[<p>OMG <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>sorry ich glaube ich brauche ine Pause...aber danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435150</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435150</guid><dc:creator><![CDATA[Kohlerer]]></dc:creator><pubDate>Mon, 29 Dec 2014 13:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 13:32:42 GMT]]></title><description><![CDATA[<p>Hör' auf Swordfish.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435151</guid><dc:creator><![CDATA[Schauder]]></dc:creator><pubDate>Mon, 29 Dec 2014 13:32:42 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 14:06:47 GMT]]></title><description><![CDATA[<p>Schauder schrieb:</p>
<blockquote>
<p>Hör' auf Swordfish.</p>
</blockquote>
<p>Ist doch wahr. Hat ein falsches delete im Destruktor, assignment operator fehlt und unnötiges langsames zweifaches Berechnen der Stringlänge. Diese Fehler und der aktuelle wären nicht passiert, wenn er std::string verwendet hätte. Und der Code wäre wesentlich kürzer.</p>
<p>BTW @TE: Kennst du Initialisierungslisten für Konstruktoren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435159</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 29 Dec 2014 14:06:47 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 14:32:20 GMT]]></title><description><![CDATA[<pre><code>#include &lt;string&gt;

class Kunde
{
    std::string name;
    std::string ort;
    int alter;
    double umsatz;
    int transaktion;
    int id;

    static int anzahl;

public:
    Kunde(const std::string &amp; name = &quot;Kein Name&quot;, const std::string &amp; ort = &quot;Kein Ort&quot;, const int alter = 0);
    Kunde(const Kunde &amp;src);

    void kaufe(double u);
    static int getAnzahl();

    void print() const;
};

#include &quot;Kunde.hpp&quot;
#include &lt;iostream&gt;

int Kunde::anzahl = 0;

Kunde::Kunde(const std::string &amp; name, const std::string &amp; ort, const int alter)
	: name(name), ort(ort), alter(alter), umsatz(0), transaktionen(0), id(Kunde::anzahl++)
{}

Kunde::Kunde(const Kunde &amp;src)
	: name(src.name), ort(src.ort), alter(src.alter), umsatz(0), transaktionen(0), id(Kunde::anzahl++)
{}

void Kunde::kaufe(double umsatz)
{
    this-&gt;umsatz += umsatz;
}

int Kunde::getAnzahl()
{
    return Kunde::anzahl;
}

void Kunde::print() const
{
    cout &lt;&lt; &quot;Kunde &quot; &lt;&lt; name &lt;&lt; &quot; aus &quot; &lt;&lt; ort
         &lt;&lt; &quot; (ID = &quot; &lt;&lt; id &lt;&lt; &quot;, &quot; &lt;&lt; alter &lt;&lt; &quot;Jahre) hatte &quot;
         &lt;&lt; transaktion &lt;&lt; &quot; Transaktion(en) und &quot; &lt;&lt; umsatz &lt;&lt; &quot; Euro Umsatz.&quot; &lt;&lt; endl;
}

#include &quot;kunde.hpp&quot;

int main() {
    Kunde a(&quot;Kunde 1&quot;);
    Kunde meiera(&quot;Meier&quot;, &quot;Esslingen&quot;, 28);

    a.print();
    meiera.print();

	return 0;
}
</code></pre>
<p>Ich habs grad einfach mal etwas aufgepeppt. Ich hoffe du stimsmt mir zu, dass das weit einfacher ist als dein Versuch mit dem Speicherverwalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435164</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 29 Dec 2014 14:32:20 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 14:36:05 GMT]]></title><description><![CDATA[<p>Kohlerer schrieb:</p>
<blockquote>
<pre><code>// ...
    double umsatz;
// ...
</code></pre>
</blockquote>
<p>Yay! again <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="🤡"
    /></p>
<p>~captcha: Cholera~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435165</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435165</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Mon, 29 Dec 2014 14:36:05 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 15:46:05 GMT]]></title><description><![CDATA[<p>Ja, Moneyz und Gleitkommazahlen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435190</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 29 Dec 2014 15:46:05 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 16:03:21 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Schauder schrieb:</p>
<blockquote>
<p>Hör' auf Swordfish.</p>
</blockquote>
<p>Diese Fehler und der aktuelle wären nicht passiert, wenn er std::string verwendet hätte. Und der Code wäre wesentlich kürzer.</p>
<p>BTW @TE: Kennst du Initialisierungslisten für Konstruktoren?</p>
</blockquote>
<p>und die Lernkurve wäre flacher. Leute, das ist eine ÜBUNG zur Speicherverwaltung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435203</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435203</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 29 Dec 2014 16:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 16:41:32 GMT]]></title><description><![CDATA[<p>mgaeckler schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Schauder schrieb:</p>
<blockquote>
<p>Hör' auf Swordfish.</p>
</blockquote>
<p>Diese Fehler und der aktuelle wären nicht passiert, wenn er std::string verwendet hätte. Und der Code wäre wesentlich kürzer.</p>
<p>BTW @TE: Kennst du Initialisierungslisten für Konstruktoren?</p>
</blockquote>
<p>und die Lernkurve wäre flacher. Leute, das ist eine ÜBUNG zur Speicherverwaltung.</p>
</blockquote>
<p>Ups, hab das nicht gesehen. Sorry.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435214</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 29 Dec 2014 16:41:32 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 17:11:09 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Schauder schrieb:</p>
<blockquote>
<p>Hör' auf Swordfish.</p>
</blockquote>
<p>Ist doch wahr...</p>
</blockquote>
<p>Kann es sein, daß Du hier ein Komma hineininterpretierst, das nicht da ist?<br />
Ich schrieb eindeutig, daß er auf Swordfish hören soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435220</guid><dc:creator><![CDATA[Schauder]]></dc:creator><pubDate>Mon, 29 Dec 2014 17:11:09 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 17:19:19 GMT]]></title><description><![CDATA[<p>Schauder schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Schauder schrieb:</p>
<blockquote>
<p>Hör' auf Swordfish.</p>
</blockquote>
<p>Ist doch wahr...</p>
</blockquote>
<p>Kann es sein, daß Du hier ein Komma hineininterpretierst, das nicht da ist?</p>
</blockquote>
<p>Jup. <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="😃"
    /> Könnte schwören da stand ein Komma. Lag vermutlich am ', das ist dann im Kopf verrutscht. Hätte den Post nicht nebenbei schreiben sollen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435222</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 29 Dec 2014 17:19:19 GMT</pubDate></item><item><title><![CDATA[Reply to Buffer ist zu klein troz dynamischem anlegen on Mon, 29 Dec 2014 23:42:41 GMT]]></title><description><![CDATA[<p>mgaeckler schrieb:</p>
<blockquote>
<p>[...] Leute, das ist eine ÜBUNG zur Speicherverwaltung.</p>
</blockquote>
<p>Dann, @Kohlerer, schreib' eine Stringklasse ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2435244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2435244</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Mon, 29 Dec 2014 23:42:41 GMT</pubDate></item></channel></rss>