<?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[Anzahl der Arrays eingeben]]></title><description><![CDATA[<p>Hallo ich möchte per Tastatureingabe bestimmen, wieviele Array-Variabeln angelegt werden sollen:</p>
<pre><code class="language-cpp">int main()
{

	int iAnzahl;
	cout &quot;Anzahl der Eintraege: &quot;;
	cin &gt;&gt; iAnzahl;

	struct PersonTyp Person[iAnzahl];

	int iZahl;
	for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
	{
		DatenAendern(Person[iZahl]);

		cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
		cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
		cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
		cout &lt;&lt; endl;
	}

 	getch();
    return 0;
}
</code></pre>
<p>Problem:<br />
Der Compiler will, dass ich aus der Variabel ne const mache.</p>
<pre><code class="language-cpp">Error	1	error C2057: expected constant expression
</code></pre>
<p>Wenn ich das mache, kann ich sie aber per Hand nicht mehr ändern.<br />
hmmm</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/248750/anzahl-der-arrays-eingeben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 18:16:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/248750.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Aug 2009 14:01:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Fri, 28 Aug 2009 14:01:15 GMT]]></title><description><![CDATA[<p>Hallo ich möchte per Tastatureingabe bestimmen, wieviele Array-Variabeln angelegt werden sollen:</p>
<pre><code class="language-cpp">int main()
{

	int iAnzahl;
	cout &quot;Anzahl der Eintraege: &quot;;
	cin &gt;&gt; iAnzahl;

	struct PersonTyp Person[iAnzahl];

	int iZahl;
	for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
	{
		DatenAendern(Person[iZahl]);

		cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
		cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
		cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
		cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
		cout &lt;&lt; endl;
	}

 	getch();
    return 0;
}
</code></pre>
<p>Problem:<br />
Der Compiler will, dass ich aus der Variabel ne const mache.</p>
<pre><code class="language-cpp">Error	1	error C2057: expected constant expression
</code></pre>
<p>Wenn ich das mache, kann ich sie aber per Hand nicht mehr ändern.<br />
hmmm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1768312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1768312</guid><dc:creator><![CDATA[Bubby]]></dc:creator><pubDate>Fri, 28 Aug 2009 14:01:15 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Fri, 28 Aug 2009 14:08:07 GMT]]></title><description><![CDATA[<p>Dynamische Sachen musst du auf dem Heap mittels new erzeugen:</p>
<pre><code class="language-cpp">int main()
{

    int iAnzahl;
    cout &quot;Anzahl der Eintraege: &quot;;
    cin &gt;&gt; iAnzahl;

    PersonTyp *Person = new PersonTyp[iAnzahl]; // Mit new anlegen

    int iZahl;
    for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
    {
        DatenAendern(Person[iZahl]);

        cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
        cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
        cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
        cout &lt;&lt; endl;
    }

   delete[] Person; // Wichtig: delete nicht vergessen!

     getch();
    return 0;
}
</code></pre>
<p>Viel einfacher wäre es natürlich, gleich einen dynamischen Container zu nehmen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1768314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1768314</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 28 Aug 2009 14:08:07 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Fri, 28 Aug 2009 14:08:52 GMT]]></title><description><![CDATA[<p>Die Grössen von Arrays müssen in C++ zur Kompilierzeit bekannt sein. Die naheligende Lösung ist ein Array per new zu allokieren.</p>
<p>Wem das aber zu viel Aufwand ist das alles selbst zu warppen, sollte einen der Standardcontainer, wie z.B <code>std::vector</code> nehmen.</p>
<pre><code class="language-cpp">#inlucde &lt;vector&gt;

int main()
{

    int iAnzahl;
    cout &quot;Anzahl der Eintraege: &quot;;
    cin &gt;&gt; iAnzahl;

    std::vector&lt;PersonTyp&gt; Person(iAnzahl);

    int iZahl;
    for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
    {
        DatenAendern(Person[iZahl]);

        cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
        cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
        cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
        cout &lt;&lt; endl;
    }

     getch();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1768315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1768315</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 28 Aug 2009 14:08:52 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Mon, 31 Aug 2009 13:50:53 GMT]]></title><description><![CDATA[<p>Danke für die Antworten.<br />
Habe es nun hinbekommen, dass man eine Anzahl eingeben kann und er entsprechende viele Einträge vornimmt.</p>
<p>Nun habe ich ein neues Problem:</p>
<p>Wenn ich meine Anzahl eingebe und mit den Eintragungen (Name, Wohnort, Email etc) beginnen möchte, lässt er beim ersten mal(nur beim ersten mal) Name aus und beginnt mit <em>Wohnort:</em>.</p>
<p>Wenn sich die Abfragen anschließend wiederholen, klappt es wunderbar und er fragt alles ab.</p>
<p>Wisst ihr wie ich das meine?<br />
Screenshot: <a href="http://img10.imageshack.us/i/screenpbw.jpg/" rel="nofollow">http://img10.imageshack.us/i/screenpbw.jpg/</a></p>
<p>Code:</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;
using namespace std;

struct PersonTyp
{
	string sName;
	string sWohnort;
	string sAlter;
	string sTelefon;
	string sEmail;	
};

void DatenAendern (PersonTyp &amp;Person)
{	
	cout &lt;&lt; &quot;Name: &quot;;
	getline(cin,Person.sName);
	cout &lt;&lt; &quot;Wohnort: &quot;;
	getline(cin,Person.sWohnort);	
	cout &lt;&lt; &quot;Alter: &quot;;
	getline(cin,Person.sAlter);	
	cout &lt;&lt; &quot;Telefon: &quot;;
	getline(cin,Person.sTelefon);
	cout &lt;&lt; &quot;E-Mail: &quot;;
	getline(cin,Person.sEmail);	
}

int main()
{

    int iAnzahl;
    cout &lt;&lt; &quot;Anzahl der Eintraege: &quot;;
    cin &gt;&gt; iAnzahl;   

    struct PersonTyp *Person = new PersonTyp[iAnzahl]; // Mit new anlegen 

    int iZahl;
    for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
    {
        DatenAendern(Person[iZahl]);

        cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
        cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
        cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
        cout &lt;&lt; endl;
    }

   delete[] Person; 

   getch();
   return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1769809</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1769809</guid><dc:creator><![CDATA[Bubby]]></dc:creator><pubDate>Mon, 31 Aug 2009 13:50:53 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Mon, 31 Aug 2009 14:08:56 GMT]]></title><description><![CDATA[<p>Schreib bei der ersten Eingabe:</p>
<pre><code class="language-cpp">cin &gt;&gt; iAnzahl;  
    cin.ignore(1,'\n');
</code></pre>
<p>Um zu verstehen wieso das so ist, solltest du dich eingehender mit Streams befassen, was allgemein ein recht lohnendes Thema ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1769823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1769823</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 31 Aug 2009 14:08:56 GMT</pubDate></item><item><title><![CDATA[Reply to Anzahl der Arrays eingeben on Mon, 31 Aug 2009 14:22:29 GMT]]></title><description><![CDATA[<p>Bubby schrieb:</p>
<blockquote>
<p>Code:</p>
<pre><code class="language-cpp">int iAnzahl;
    cout &lt;&lt; &quot;Anzahl der Eintraege: &quot;;
    cin &gt;&gt; iAnzahl;
</code></pre>
</blockquote>
<p>cin &gt;&gt; iAnzahl liest nur die Zahl, also nicht mehr den Zeilenvorschub.</p>
<p>Bubby schrieb:</p>
<blockquote>
<pre><code class="language-cpp">struct PersonTyp *Person = new PersonTyp[iAnzahl]; // Mit new anlegen
</code></pre>
</blockquote>
<p>Das wollen wir uns ganz schnell mal wieder abgewöhnen. Das &quot;struct&quot; ist in C++ hier überflüssig. Nimm</p>
<pre><code class="language-cpp">std::vector&lt;PersonenTyp&gt; Person; // oder besser &quot;personen&quot;
</code></pre>
<p>Bubby schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int iZahl;
    for ( iZahl=0; iZahl&lt;iAnzahl; iZahl++)
    {
</code></pre>
</blockquote>
<pre><code class="language-cpp">Person.push_back(PersonTyp());
        DatenAendern(Person.back());
</code></pre>
<p>Bubby schrieb:</p>
<blockquote>
<pre><code class="language-cpp">cout &lt;&lt; &quot;\nNeuer Eintrag: \n&quot;;
        cout &lt;&lt; &quot;\nDein Name ist:     \t&quot;&lt;&lt;Person[iZahl].sName&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Wohnort ist: \t&quot;&lt;&lt;Person[iZahl].sWohnort&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Alter ist: \t&quot;&lt;&lt;Person[iZahl].sAlter&lt;&lt;endl;
        cout &lt;&lt; &quot;Deine Telefonnr ist: \t&quot;&lt;&lt;Person[iZahl].sTelefon&lt;&lt;endl;
        cout &lt;&lt; &quot;Dein Email ist: \t&quot;&lt;&lt;Person[iZahl].sEmail&lt;&lt;endl;
        cout &lt;&lt; endl;
    }

   delete[] Person;
</code></pre>
</blockquote>
<p>Das delete[] Person ist mit dem Vektor überflüssig. Toll, oder?</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1769829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1769829</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Mon, 31 Aug 2009 14:22:29 GMT</pubDate></item></channel></rss>