<?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[Vector belegung mit Objekten]]></title><description><![CDATA[<p>erstmal auf englisch, weil mein akku gleich leer ist...<br />
ich habs auch schon unter <a href="http://cplusplus.com" rel="nofollow">cplusplus.com</a> gepostet...</p>
<p>Hello guys, i've just registered and i hope to find a fast solution.</p>
<p>my job is to read in a master data file of several persons.<br />
this data should be display by a winform gui...</p>
<p>this is the structure of the file is<br />
id;surname;forename;size;sex<br />
1;mustermann;max;1.95;m</p>
<p>now my problem:</p>
<pre><code class="language-cpp">// PersonalVerwaltung.cpp: Hauptprojektdatei.

#include &quot;stdafx.h&quot;
#include &quot;Form1.h&quot;
#include &quot;Person.h&quot;
#include &lt;vector&gt;

using namespace PersonalVerwaltung;

void readPersonsFromFile(vector&lt;CPerson&gt;*);

[STAThreadAttribute]
int main(array&lt;System::String ^&gt; ^args)
{
	// Aktivieren visueller Effekte von Windows XP, bevor Steuerelemente erstellt werden
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	//personList = 
	vector&lt;CPerson&gt;* personList= new vector&lt;CPerson&gt;;
	readPersonsFromFile(personList);
	// Hauptfenster erstellen und ausführen
	Application::Run(gcnew Form1(personList));

	return 0;
}

void readPersonsFromFile(vector&lt;CPerson&gt; *t_PersonList)
{
	/*	Funktioniert mit direkter Zuweisung
	CPerson *t_Person = new CPerson(1, &quot;Mustermann&quot;, &quot;Max&quot;,1.95, &quot;m&quot;);
	t_PersonList-&gt;push_back(*t_Person);
	t_Person = new CPerson(1, &quot;Musterfrau&quot;, &quot;Birgit&quot;,1.73, &quot;w&quot;);
	t_PersonList-&gt;push_back(*t_Person);*/

	/**Variante mit auslesen aus Datei****************************************/
	int i = 0;			//Laufindex für Auslesen
	char buffer[150];
	FILE *f;

	f=fopen(&quot;Personal.txt&quot;,&quot;r&quot;);
	for(i=0;fgets(buffer,sizeof buffer,f)!=NULL;i++)
	{
		t_PersonList-&gt;push_back(*new CPerson(atoi(strtok(buffer,&quot;;&quot;)),
											strtok(NULL,&quot;;&quot;),
											strtok(NULL,&quot;;&quot;),
											atof(strtok(NULL,&quot;;&quot;)),
											strtok(NULL,&quot;;&quot;)));

	}

}
</code></pre>
<p>if i code it like this, the vector is full of one data --&gt;only one person in every row...in debuggin mode, i see, that in every row the addresses for every property is the same...<br />
i've tried to avoid this by taking</p>
<pre><code class="language-cpp">t_PersonList-&gt;push_back(*new CPerson(atoi(strtok(buffer,&quot;;&quot;)), ...etc.
</code></pre>
<p>any suggestions?</p>
<p>and the second problem is:<br />
in the main method i'm creating a vector personList--&gt; this is given to the reader-method by &quot;call by reference&quot;</p>
<p>nethertheless the temporary t_personList is filled all with the same data...<br />
the &quot;main&quot; personList has the same contents except the char-fieds...<br />
in debugging mode there is &quot;&quot;</p>
<p>my latin is over...</p>
<p>hope you can understand me <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/topic/281717/vector-belegung-mit-objekten</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 13:10:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/281717.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Feb 2011 19:04:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 19:04:45 GMT]]></title><description><![CDATA[<p>erstmal auf englisch, weil mein akku gleich leer ist...<br />
ich habs auch schon unter <a href="http://cplusplus.com" rel="nofollow">cplusplus.com</a> gepostet...</p>
<p>Hello guys, i've just registered and i hope to find a fast solution.</p>
<p>my job is to read in a master data file of several persons.<br />
this data should be display by a winform gui...</p>
<p>this is the structure of the file is<br />
id;surname;forename;size;sex<br />
1;mustermann;max;1.95;m</p>
<p>now my problem:</p>
<pre><code class="language-cpp">// PersonalVerwaltung.cpp: Hauptprojektdatei.

#include &quot;stdafx.h&quot;
#include &quot;Form1.h&quot;
#include &quot;Person.h&quot;
#include &lt;vector&gt;

using namespace PersonalVerwaltung;

void readPersonsFromFile(vector&lt;CPerson&gt;*);

[STAThreadAttribute]
int main(array&lt;System::String ^&gt; ^args)
{
	// Aktivieren visueller Effekte von Windows XP, bevor Steuerelemente erstellt werden
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	//personList = 
	vector&lt;CPerson&gt;* personList= new vector&lt;CPerson&gt;;
	readPersonsFromFile(personList);
	// Hauptfenster erstellen und ausführen
	Application::Run(gcnew Form1(personList));

	return 0;
}

void readPersonsFromFile(vector&lt;CPerson&gt; *t_PersonList)
{
	/*	Funktioniert mit direkter Zuweisung
	CPerson *t_Person = new CPerson(1, &quot;Mustermann&quot;, &quot;Max&quot;,1.95, &quot;m&quot;);
	t_PersonList-&gt;push_back(*t_Person);
	t_Person = new CPerson(1, &quot;Musterfrau&quot;, &quot;Birgit&quot;,1.73, &quot;w&quot;);
	t_PersonList-&gt;push_back(*t_Person);*/

	/**Variante mit auslesen aus Datei****************************************/
	int i = 0;			//Laufindex für Auslesen
	char buffer[150];
	FILE *f;

	f=fopen(&quot;Personal.txt&quot;,&quot;r&quot;);
	for(i=0;fgets(buffer,sizeof buffer,f)!=NULL;i++)
	{
		t_PersonList-&gt;push_back(*new CPerson(atoi(strtok(buffer,&quot;;&quot;)),
											strtok(NULL,&quot;;&quot;),
											strtok(NULL,&quot;;&quot;),
											atof(strtok(NULL,&quot;;&quot;)),
											strtok(NULL,&quot;;&quot;)));

	}

}
</code></pre>
<p>if i code it like this, the vector is full of one data --&gt;only one person in every row...in debuggin mode, i see, that in every row the addresses for every property is the same...<br />
i've tried to avoid this by taking</p>
<pre><code class="language-cpp">t_PersonList-&gt;push_back(*new CPerson(atoi(strtok(buffer,&quot;;&quot;)), ...etc.
</code></pre>
<p>any suggestions?</p>
<p>and the second problem is:<br />
in the main method i'm creating a vector personList--&gt; this is given to the reader-method by &quot;call by reference&quot;</p>
<p>nethertheless the temporary t_personList is filled all with the same data...<br />
the &quot;main&quot; personList has the same contents except the char-fieds...<br />
in debugging mode there is &quot;&quot;</p>
<p>my latin is over...</p>
<p>hope you can understand me <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/2017473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017473</guid><dc:creator><![CDATA[DMDTT]]></dc:creator><pubDate>Sun, 06 Feb 2011 19:04:45 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 20:11:12 GMT]]></title><description><![CDATA[<p>Ich gehe mal von deinem ersten Satz her davon aus, dass du Deutsch verstehst:</p>
<p>Wow, du schaffst es tatsächlich, einen vector nicht nur mit einem, nein sogar mit zwei Speicherlecks zu verbinden - ein kleines Kunststück an sich. Außerdem schöne Verwendung von C Routinen ohne jede Prüfung und undefinierte Abarbeitungsreihenfolge. Dein Code hat so viele Probleme, da lässt sich gar nicht sagen was letztendlich das Problem ist was du gerade suchst. Ich empfehle vollständiges Neuschreiben nachdem du dir ein einigermaßen gutes C++-Anfängerbuch angesehen hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017508</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 06 Feb 2011 20:11:12 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 20:17:40 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Außerdem schöne Verwendung von C Routinen ohne jede Prüfung und undefinierte Abarbeitungsreihenfolge.</p>
</blockquote>
<p>Und gewürzt mit C++/CLI...</p>
<p>@DMDTT: Welche Sprache willst du eigentlich schreiben? C, C++ oder C++/CLI?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017516</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Sun, 06 Feb 2011 20:17:40 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 20:29:38 GMT]]></title><description><![CDATA[<p>Und beim Neuschreiben könntest du auch gleich auf die C-Präfixe, manuelle Speicherverwaltung und Deklaration weit vom Benutzungspunkt verzichten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017526</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 06 Feb 2011 20:29:38 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:05:59 GMT]]></title><description><![CDATA[<p>hallo...also das das hier so abläuft hätte ich nicht gedacht...</p>
<p>ich komme aus der java ecke...und bei einer &quot;probebewerbung&quot; wurde mir diese aufgabe gesgtellt...</p>
<p>ich würde es begrüßen wenn ihr mir eindeutiger weiterhelfen würdet...</p>
<p>speicherleck? wieso?</p>
<p>c++/cli....c/c++ ...entschulidigt...wo der unterschied liegt keine ahung...alleine aus dem grund, dass ich mich auf eine c# stelle beworben habe...nun ich mache visual studio 2010 auf, c++ , winform anwendung...</p>
<p>danke im voraus für gutgemeinte ratschläge...die zeit für ein c++ buch ist nich da...</p>
<p>das mit dem speicherleck, interessiert mich wirklich <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/2017549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017549</guid><dc:creator><![CDATA[DMDTT]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:05:59 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:12:18 GMT]]></title><description><![CDATA[<p>DMDTT schrieb:</p>
<blockquote>
<p>alleine aus dem grund, dass ich mich auf eine c# stelle beworben habe...</p>
</blockquote>
<p>Das wird ja immer besser <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>Ein Speicherleck hast du, weil du in C++(/CLI) <code>new</code> benutzt, ohne den Speicher mit <code>delete</code> wieder freizugeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017554</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:12:18 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:14:29 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>DMDTT schrieb:</p>
<blockquote>
<p>alleine aus dem grund, dass ich mich auf eine c# stelle beworben habe...</p>
</blockquote>
<p>Das wird ja immer besser <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>Ein Speicherleck hast du, weil du in C++(/CLI) <code>new</code> benutzt, ohne den Speicher mit <code>delete</code> wieder freizugeben.</p>
</blockquote>
<p>entschuldige...was soll das denn nun...<br />
wo und wie sollte ich den speicher freigeben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017557</guid><dc:creator><![CDATA[DMDTT]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:14:29 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:19:12 GMT]]></title><description><![CDATA[<p>Sag uns zuerst, zu welcher Sprache du nun eine Frage stellen willst. Der Code ist C/C++/CLI, und du sprichst von C#. Und vielleicht ganz wenig Zeit solltest du schon aufwenden, um eine dieser Sprachen zu beherrschen. Man bekommt nämlich das Gefühl, du hättest keine Ahnung und versuchtest irgendwas zusammenzubasteln.</p>
<p>Abgesehen davon findest du mit den Stichworten Speicherverwaltung, new, delete schon sehr viel (über die Forensuche oder auf einer Suchmaschine).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017561</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:19:12 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:24:40 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Sag uns zuerst, zu welcher Sprache du nun eine Frage stellen willst. Der Code ist C/C++/CLI, und du sprichst von C#. Und vielleicht ganz wenig Zeit solltest du schon aufwenden, um eine dieser Sprachen zu beherrschen. Man bekommt nämlich das Gefühl, du hättest keine Ahnung und versuchtest irgendwas zusammenzubasteln.</p>
<p>Abgesehen davon findest du mit den Stichworten Speicherverwaltung, new, delete schon sehr viel (über die Forensuche oder auf einer Suchmaschine).</p>
</blockquote>
<p>Der Code soll natürlich mich c++ geschrieben werden...ich denke im genauen,</p>
<p>wir haben im studium mit c++ opengl programmiert, entschuldige bitte, dass ich mir da um sowas keine gedanken machen musst...delete pujh...höre ich jetzt in der anwendung das erste mal.......</p>
<p>japp natürlich versuche ich teilweise irgendwas zusammenzubasteln...da mein favorit java ist, ist es nicht ganz so einfach, aber mit ein paar guten ratschlägen, wie ich meinen &quot;zusammengeschusterten&quot; code aufpeppen und zu einem annehmbaren ergebnis kommen könnte, wäre ich zufrieden...das soll jetzt aber nicht so eine sache &quot;macht meine arbeit&quot; sein...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017566</guid><dc:creator><![CDATA[DMDTT]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:30:47 GMT]]></title><description><![CDATA[<p>ok das mit der speicherfreigabe ist klar :).-..</p>
<p>nun aber zum speicherleck?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017568</guid><dc:creator><![CDATA[DMDTT]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:44:37 GMT]]></title><description><![CDATA[<p>DMDTT schrieb:</p>
<blockquote>
<p>ok das mit der speicherfreigabe ist klar :).-..</p>
<p>nun aber zum speicherleck?</p>
</blockquote>
<p>Bist du sicher, dass es dir klar ist? Denn damit würde sich auch das Speicherleck erledigen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017573</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:44:37 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Sun, 06 Feb 2011 21:45:20 GMT]]></title><description><![CDATA[<p>DMDTT schrieb:</p>
<blockquote>
<p>ok das mit der speicherfreigabe ist klar :).-..</p>
<p>nun aber zum speicherleck?</p>
</blockquote>
<p><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="😕"
    /> Ist es nun klar oder nicht?</p>
<p>Man merkt einduetig, dass du von Java kommst mit dem vielen new. In C++ brauchst du für solchen Anfängerkram niemals new. Da macht man alles entweder mit automatischen Objekten oder man kapselt das new in Klassen die RAII befolgen (z.B. alle Container der STL). Außerdem ist ein guter Leitfaden für absolute Anfänger, dass man Pointer ebenfalls nicht braucht und dass man Funktionen aus der C-Bibliothek ebenfalls nicht braucht. Denn wenn man keine Ahnung hat, geht das garantiert schief. Und genau das beschreibt deinen Code.</p>
<p>Falls du Begriffe aus meinem Beitrag nicht verstehst, versuch sie nachzuschlagen.</p>
<p>Außerdem verzeih mir, wenn ich keine Lust habe, eine Bewerbung für dich zu schreiben. Wenn du von C/C++/CLI/C# (entscheide dich mal!) keine Ahnung hast und auch keine Zeit hast, etwas zu lernen, dann bist du einfach nicht qualifiziert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017574</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 06 Feb 2011 21:45:20 GMT</pubDate></item><item><title><![CDATA[Reply to Vector belegung mit Objekten on Mon, 07 Feb 2011 16:38:58 GMT]]></title><description><![CDATA[<p>DMDTT schrieb:</p>
<blockquote>
<p>hallo...also das das hier so abläuft hätte ich nicht gedacht...</p>
</blockquote>
<p>Was erwartest du von einem Beitrag der definitiv nicht C++, sondern C++/CLI (was eine gänzlich andere Sprache ist) mit C und C++ mixt. WinForms läuft nicht mit C++, sondern Ausschließlich mit C++/CLI was eine von Microsoft entwickelte (und zumindest was den Compilersupport angeht nahezu eingestampfte) Sprache ist.</p>
<p>DMDTT schrieb:</p>
<blockquote>
<p>ich komme aus der java ecke...</p>
</blockquote>
<p>Java wird auf einer wesentlich höheren Ebene programmiert, hat einen Garbage Collector (Was C# auch hat, und C++/CLI wenn man mit .Net-Typen arbeitet, die mit gcnew alloziert werden).</p>
<p>DMDTT schrieb:</p>
<blockquote>
<p>ich würde es begrüßen wenn ihr mir eindeutiger weiterhelfen würdet...</p>
</blockquote>
<p>Dafür müsste man aber erstmal wissen wie man dir helfen kann (und dazu müsste man wiederum wissen was für eine Zielsprache verwendet werden soll).</p>
<p>DMDTT schrieb:</p>
<blockquote>
<p>alleine aus dem grund, dass ich mich auf eine c# stelle beworben habe...</p>
</blockquote>
<p>Und C# hat nun nahezu garnichts mit C, C++ oder C++/CLI zu tun. Wenn es C# sein soll, solltest du auch C# versuchen (Da du aus der Java-Ecke kommst könnte für dich das Buch 22 von folgender <a href="http://www.c-plusplus.net/forum/281570" rel="nofollow">Liste</a> vielleicht helfen, soviel ich mich erinnere hebt es explizit Unterschiede zu Java auf der einen, und C++ auf der anderen Seite hervor. Selbst wenn es nicht mehr die aktuellste Auflage ist, wäre dies ein Einstieg).</p>
<p>DMDTT schrieb:</p>
<blockquote>
<p>nun ich mache visual studio 2010 auf, c++ , winform anwendung...</p>
</blockquote>
<p>Für C++ nimm bitte &quot;Win32 Console Application&quot;, und Leeres Projekt. Dann füge eine main.cpp hinzu. Für C# nimm bitte auch gleich ein C#-Template.</p>
<p>DMDTT schrieb:</p>
<blockquote>
<p>...die zeit für ein c++ buch ist nich da...</p>
</blockquote>
<p>Dann solltest du dir überlegen worauf du dich bewirbst. Ganz davon abgesehen bezweifel ich, das ihr mit OpenGL (wenn ihr wirklich C++ verwendet habt) kein delete kennen gelernt habt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2017885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2017885</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 07 Feb 2011 16:38:58 GMT</pubDate></item></channel></rss>