<?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[Funktionsübergreifendes Array]]></title><description><![CDATA[<p>Hey,</p>
<p>ich hab gerade ein kleines Problem...<br />
Ich fange an einen Vokabeltrainer für den Lateinunterricht zu schreiben.</p>
<p>Jetzt nach dem Einlesen der Vokabelliste stelle ich fest, dass die Strings &amp; Variablen nicht mehr funktionieren.</p>
<p>Das Problem liegt denke ich darin dass das einlesen in einer Funktion geschieht und ich mich aktuell in einer anderen Funktion befinde.</p>
<p>Theoretisch könnte ich die Variable Array usw einfach als static bzw. global definieren. (Static wird kompiliert - geht trotzdem nicht /// global wird nicht compiliert - geht auch nicht).<br />
Was kann ich da noch machen.</p>
<p>Mein aktueller Code:</p>
<pre><code class="language-cpp">int hoehe = 0;
	int breite = 0;
	int vokabelzaehler = 0;
	string temp = &quot;&quot;;
	string lektion = &quot;&quot;;
	string vokabel [6][100];

	ifstream lektiontxt(&quot;lektion.txt&quot;);
	getline(lektiontxt, lektion);

	ifstream datei(lektion.c_str());

	while(!datei.eof())
	{
        getline(datei, temp);
        vokabel [breite][hoehe] = temp;

        breite =+ 1;
        if(breite &gt;= 6)
        {
            breite = 0;
            hoehe =+ 1;
        };

        vokabelzaehler = hoehe;
        }
</code></pre>
<p>eigentlich müssen nur die variablen, strings und das array oben geändert werden. Ich weiß aber nicht mehr wie...</p>
<p>Bin dankbar für jede Hilfe!</p>
<p>MfG: Eric</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250969/funktionsübergreifendes-array</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 17:58:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250969.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 27 Sep 2009 14:13:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:13:02 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>ich hab gerade ein kleines Problem...<br />
Ich fange an einen Vokabeltrainer für den Lateinunterricht zu schreiben.</p>
<p>Jetzt nach dem Einlesen der Vokabelliste stelle ich fest, dass die Strings &amp; Variablen nicht mehr funktionieren.</p>
<p>Das Problem liegt denke ich darin dass das einlesen in einer Funktion geschieht und ich mich aktuell in einer anderen Funktion befinde.</p>
<p>Theoretisch könnte ich die Variable Array usw einfach als static bzw. global definieren. (Static wird kompiliert - geht trotzdem nicht /// global wird nicht compiliert - geht auch nicht).<br />
Was kann ich da noch machen.</p>
<p>Mein aktueller Code:</p>
<pre><code class="language-cpp">int hoehe = 0;
	int breite = 0;
	int vokabelzaehler = 0;
	string temp = &quot;&quot;;
	string lektion = &quot;&quot;;
	string vokabel [6][100];

	ifstream lektiontxt(&quot;lektion.txt&quot;);
	getline(lektiontxt, lektion);

	ifstream datei(lektion.c_str());

	while(!datei.eof())
	{
        getline(datei, temp);
        vokabel [breite][hoehe] = temp;

        breite =+ 1;
        if(breite &gt;= 6)
        {
            breite = 0;
            hoehe =+ 1;
        };

        vokabelzaehler = hoehe;
        }
</code></pre>
<p>eigentlich müssen nur die variablen, strings und das array oben geändert werden. Ich weiß aber nicht mehr wie...</p>
<p>Bin dankbar für jede Hilfe!</p>
<p>MfG: Eric</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784943</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784943</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:13:02 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:19:04 GMT]]></title><description><![CDATA[<p>Du übergibst eine Referenz der Funktion. So in die Richtung:</p>
<pre><code class="language-cpp">void fill_voc ( std::vector&lt;std::string&gt;&amp; voc )
{
 // fülle voc
}

int main ()
{
 std::vector&lt;std::string&gt; voc;

 fill_voc ( voc );

 // voc ist nun gefüllt
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1784948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784948</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:19:04 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:23:01 GMT]]></title><description><![CDATA[<p>Dann wird am Ende aber alles nochmal eingelesen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784951</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:23:01 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:26:31 GMT]]></title><description><![CDATA[<p>Nein, warum? - Du musst die Funktion ja lediglich 1x aufrufen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784954</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:26:31 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:28:44 GMT]]></title><description><![CDATA[<p>Der Button wird aber mehrmals geklickt.<br />
Also bei dir: Voc ist nun gefüllt.</p>
<p>Wird da nicht jedes mal wenn die Funktion / Button geklickt wird, nochmal alles eingelesen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784955</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:28:44 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 14:32:06 GMT]]></title><description><![CDATA[<p>Keine Ahung, was du machst, wenn du einen Button klickst, aber bei mir wird die Funktion lediglich einmal aufgerufen. Kommt halt drauf an, was du in dem Button machst..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784959</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 27 Sep 2009 14:32:06 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 15:06:24 GMT]]></title><description><![CDATA[<p>Das funktioniert aber immernoch nicht so wie ich das möchte...</p>
<p>wofür ist std::vector<a href="std::string" rel="nofollow">std::string</a> voc; und std::vector<a href="std::string" rel="nofollow">std::string</a>&amp; voc ???</p>
<p>Der Compiler sagt das voc nicht deklariert sei und vector is not a member of std.<br />
std:: kann ich aber durch das using namespace std; eigentlich weglassen.<br />
Das selbe Problem besteht weiterhin.</p>
<p>Ich hab das std::vector<a href="std::string" rel="nofollow">std::string</a>&amp; voc mal weggelassen und eine normale Funktion gemacht... auf die bei jedem Button-klick zurückgegriffen wird.<br />
Die Variablen sind trotzdem &quot;weg&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1784981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784981</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Sun, 27 Sep 2009 15:06:24 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Sun, 27 Sep 2009 15:24:30 GMT]]></title><description><![CDATA[<p>Das war rein prinzipiell, wies geht. Du musst an die Funktion eine Referenz (oder halt auch einen Zeiger) auf die Liste gebeben, dann kannst du die Liste füllen und wenn die Funktion fertig ist, hat der Aufrufer seine gefüllte Liste.</p>
<p>Das <code>std::vector</code> war ein Hinweis, dass es mit einem Standardcontainer wesentlich einfacher geht, als mit einem Array. (ist auch dynamisch).</p>
<p>btw:</p>
<blockquote>
<pre><code class="language-cpp">breite =+ 1;
        if(breite &gt;= 6)
        {
            breite = 0;
            hoehe =+ 1;
        };
</code></pre>
</blockquote>
<p>Bist du sicher, dass du hier 'breite =+ 1' haben willst? - Da weist du nämlich breite immer 1 zu. Mehr nicht. Wenn du inkrementieren willst, dann mach das so:</p>
<pre><code class="language-cpp">breite += 1; // oder ++breite;
        if(breite &gt;= 6)
        {
            breite = 0;
            hoehe += 1; // oder alternativ ++hoehe;
        };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1784992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1784992</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 27 Sep 2009 15:24:30 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 13:29:02 GMT]]></title><description><![CDATA[<p>Ich habe es jetzt etwas anders Probiert.<br />
Meine Überlegung:<br />
Funktion in Funktion aufrufen -&gt; Strings können genutzt werden<br />
Funktion mit return &amp; strings beenden -&gt; Strings können in der Buttonclickfunktion verwendet werden.</p>
<p>Das müsste theoretisch funktionieren. Der Compiler bringt aber Fehler bei dem { der Funktion vokabeluebergabe() -&gt; &quot;a function-definition is not allowed here before '{' token&quot;.<br />
Ich weis nicht was daran falsch sein soll.</p>
<p>Wisst ihr was man da machen kann?<br />
PS: Ich will nicht jedes mal nochmal alles neu einlesen!</p>
<pre><code class="language-cpp">einlesen()	
{
	int hoehe = 0;
	int breite = 0;
	int vokabelzaehler = 0;
	string temp = &quot;&quot;;
	string lektion = &quot;&quot;;
	string vokabel [6][100];

	ifstream lektiontxt(&quot;lektion.txt&quot;);
	getline(lektiontxt, lektion);

	ifstream datei(lektion.c_str());

	while(!datei.eof())
	{
        getline(datei, temp);
        vokabel [breite][hoehe] = temp;

        breite =+ 1;
        if(breite &gt;= 6)
        {
            breite = 0;
            hoehe =+ 1;
        };

        vokabelzaehler = hoehe;
    }

	   void vokabeluebergabe(int hoch, int breit1, int breit2, int breit3, int breit4, int breit5, int breit6)
       {
            string vokabel1 = vokabel [breit1][hoch];
            string vokabel2 = vokabel [breit2][hoch];
            string vokabel3 = vokabel [breit3][hoch];
            string vokabel4 = vokabel [breit4][hoch];
            string vokabel5 = vokabel [breit5][hoch];
            string vokabel6 = vokabel [breit6][hoch];

            return vokabel1 + vokabel2 + vokabel3 + vokabel4 + vokabel5 + vokabel6; 
         }

}

void LVTFrm::WxButton1Click(wxCommandEvent&amp; event)
{
    vokabeluebergabe(3,1,2,3,4,5,6);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1785418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785418</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Mon, 28 Sep 2009 13:29:02 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 14:14:48 GMT]]></title><description><![CDATA[<p>Das hatten wir vor kurzem schon: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-250919.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-250919.html</a></p>
<p>Lokale Funktionen sind in C++ nicht erlaubt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785453</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 28 Sep 2009 14:14:48 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 15:49:36 GMT]]></title><description><![CDATA[<p>Hast du dann eine andere Variante, wie ich auf das array auch noch von einer anderen Stelle zugreifen kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785515</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Mon, 28 Sep 2009 15:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 16:11:04 GMT]]></title><description><![CDATA[<p>Parameter ist das magische Wort. Und wenn du kein anständiges Design hin bringst, dann gehts halt über globale Variablen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785532</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 28 Sep 2009 16:11:04 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 16:21:06 GMT]]></title><description><![CDATA[<p>Mit Parametern habe ich doch gearbeitet... siehe letzten Post...<br />
Das es nicht möglich ist eine Funktion in eine Funktion zu bringen stellt für mich ein Problem dar, weil ich nicht die ganze Datei immer wieder neu einlesen möchte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785539</guid><dc:creator><![CDATA[www.Progalisten.de]]></dc:creator><pubDate>Mon, 28 Sep 2009 16:21:06 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsübergreifendes Array on Mon, 28 Sep 2009 16:28:49 GMT]]></title><description><![CDATA[<p>Du machst da einfach eine Vokablen Klasse und dann hast du da eine Funktion, die z.B load heisst und wo du das File angeben kannst. Dann liest du das ganze ein und hälst dann die Liste in der Klasse. Und dann kannst du weitere Funktionen definieren.</p>
<p>Ich habe irgendwie das Gefühl, dass du die Grundlagen nochmal anschauen solltest. Du hast da eine Funktion ohne Rückgabetyp und die (fälschlicherweise) in der Funktion definierte Funktion hat den Rückgabetyp void du gibst aber etwas zurück..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785540</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 28 Sep 2009 16:28:49 GMT</pubDate></item></channel></rss>