<?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[Problem mit Zugriff auf ein Struct innerhalb eines Arrays]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

int main()
{
    struct car{
           char make[];
           int yearbuilt;
    };

cout &lt;&lt; &quot;how many cars do you want to be cataloged?&quot; &lt;&lt; endl;
int a;
cin &gt;&gt; a;
for (int a; a&gt;0; a--){
    car *pointer=new car[a];
    cout &lt;&lt; &quot;please enter the car's make: &quot; &lt;&lt; endl;
    cin.getline(pointer[a].make[],20);
    cout &lt;&lt; &quot;please enter the year it was built&quot; &lt;&lt; endl;
    cin &gt;&gt; pointer[a].yearbuilt;
}

system(&quot;PAUSE&quot;);
return 0;
}
</code></pre>
<p>leider kann dieses programm nicht kompiliert werden, irgendwas an der zeile &quot;cin.getline(pointer[a].make[],20);&quot; ist falsch...<br />
die absicht wäre, dass so viele dynamische arrays für das car-struct erzeugt werden, wie der benutzer autos abspeichern will. dann soll er aufgefordert werden, den autonamen einzugeben, der dann im entsprechenden struct innerhalb des arrays abgespeichert werden soll. offenbar scheint an dieser stelle was am code nicht zu stimmen, habe schon verschiedene varianten ausprobiert aber komme nicht drauf wie ich das richtig schreiben soll...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/203505/problem-mit-zugriff-auf-ein-struct-innerhalb-eines-arrays</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 14:02:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/203505.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Jan 2008 14:19:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Zugriff auf ein Struct innerhalb eines Arrays on Wed, 23 Jan 2008 14:19:09 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

int main()
{
    struct car{
           char make[];
           int yearbuilt;
    };

cout &lt;&lt; &quot;how many cars do you want to be cataloged?&quot; &lt;&lt; endl;
int a;
cin &gt;&gt; a;
for (int a; a&gt;0; a--){
    car *pointer=new car[a];
    cout &lt;&lt; &quot;please enter the car's make: &quot; &lt;&lt; endl;
    cin.getline(pointer[a].make[],20);
    cout &lt;&lt; &quot;please enter the year it was built&quot; &lt;&lt; endl;
    cin &gt;&gt; pointer[a].yearbuilt;
}

system(&quot;PAUSE&quot;);
return 0;
}
</code></pre>
<p>leider kann dieses programm nicht kompiliert werden, irgendwas an der zeile &quot;cin.getline(pointer[a].make[],20);&quot; ist falsch...<br />
die absicht wäre, dass so viele dynamische arrays für das car-struct erzeugt werden, wie der benutzer autos abspeichern will. dann soll er aufgefordert werden, den autonamen einzugeben, der dann im entsprechenden struct innerhalb des arrays abgespeichert werden soll. offenbar scheint an dieser stelle was am code nicht zu stimmen, habe schon verschiedene varianten ausprobiert aber komme nicht drauf wie ich das richtig schreiben soll...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442033</guid><dc:creator><![CDATA[MrWulf]]></dc:creator><pubDate>Wed, 23 Jan 2008 14:19:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Zugriff auf ein Struct innerhalb eines Arrays on Wed, 23 Jan 2008 14:21:36 GMT]]></title><description><![CDATA[<p>Schon die Zeile &quot;char make[];&quot; ist falsch - da fehlt die Größenangabe für das Array. Wenn du das korrigiert hast, ist bei deinem getline() Aufruf das leere Klammerpaar hinter 'make' überflüssig.</p>
<p>(Ein persönlicher Tip: Mach dir das Leben leichter und verwende std::string und std::vector&lt;&gt;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442036</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442036</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 23 Jan 2008 14:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Zugriff auf ein Struct innerhalb eines Arrays on Wed, 23 Jan 2008 14:25:30 GMT]]></title><description><![CDATA[<p>packe die speicher reservierung vor die schleife</p>
<pre><code class="language-cpp">car *pointer=new car[a];
</code></pre>
<p>und gib den speicher wieder frei am ende des programms</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442041</guid><dc:creator><![CDATA[Ramsis]]></dc:creator><pubDate>Wed, 23 Jan 2008 14:25:30 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Zugriff auf ein Struct innerhalb eines Arrays on Wed, 23 Jan 2008 19:57:19 GMT]]></title><description><![CDATA[<p>danke für eure tipps! hab das soweit auch umgesetzt und noch das progi fertiggeschrieben, lässt sich soweit auch kompilieren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

int main()
{
    struct car{
           char make[20];
           int yearbuilt;
    };

cout &lt;&lt; &quot;how many cars do you want to be cataloged?&quot; &lt;&lt; endl;
int a;
int b=a;
cin &gt;&gt; a;
car *pointer=new car[a];
for (int a=a-1; a&gt;=0; a--){
    cout &lt;&lt; &quot;car nr.1:&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;please enter the car's make: &quot; &lt;&lt; endl;
    cin.getline(pointer[a].make,20);
    cout &lt;&lt; &quot;please enter the year it was built:&quot; &lt;&lt; endl;
    cin &gt;&gt; pointer[a].yearbuilt;
}

cout &lt;&lt; &quot;here is your catalog:&quot; &lt;&lt; endl;
for (int b=b-1; b&gt;=0; b--){
    cout &lt;&lt; pointer[a].make &lt;&lt; &quot;\t&quot; &lt;&lt; pointer[a].yearbuilt &lt;&lt; endl;
}

delete [] pointer; 
system(&quot;PAUSE&quot;);
return 0;
}
</code></pre>
<p>nur kommt das programm nicht sehr weit, sobald man die anzahl autos eingibt, deren daten man abspeichern will, kommt noch die eingabeaufforderung für das modell, doch das programm &quot;stürzt&quot; mit der typischen problembericht-senden fehlermeldung von windows ab... dabei hab ich das erzeugte array am ende des programms wieder gelöscht. was mach ich falsch??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442317</guid><dc:creator><![CDATA[MrWulf]]></dc:creator><pubDate>Wed, 23 Jan 2008 19:57:19 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Zugriff auf ein Struct innerhalb eines Arrays on Wed, 23 Jan 2008 21:53:04 GMT]]></title><description><![CDATA[<p>Zeitvertreib <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

struct car{
	char make[20];
	int yearbuilt;
};

int main()
{
	int a = 0;

	cout &lt;&lt; &quot;how many cars do you want to be cataloged?&quot; &lt;&lt; endl;
	cin &gt;&gt; a;

	if(a) {

		car *pointer=new car[a];

		for (int i=0; i &lt; a; i++)
		{
			cout &lt;&lt; &quot;car nr.&quot; &lt;&lt; i + 1 &lt;&lt; &quot;:&quot; &lt;&lt; endl;
			cout &lt;&lt; &quot;please enter the car's make: &quot;;
			cin.ignore();
			cin.getline(pointer[i].make,20);
			cout &lt;&lt; endl;

			cout &lt;&lt; &quot;please enter the year it was built: &quot;;
			cin &gt;&gt; pointer[i].yearbuilt;
		}

		cout &lt;&lt; &quot;here is your catalog: &quot; &lt;&lt; endl;
		for (int i=0; i &lt; a; i++)
		{
			cout &lt;&lt; pointer[i].make &lt;&lt; &quot;\t&quot; &lt;&lt; pointer[i].yearbuilt &lt;&lt; endl;
		}

		delete [] pointer;
	}

	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1442401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442401</guid><dc:creator><![CDATA[Ramsis]]></dc:creator><pubDate>Wed, 23 Jan 2008 21:53:04 GMT</pubDate></item></channel></rss>