<?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[wie weise ich gepopte list items einer variable zu ?]]></title><description><![CDATA[<p>hi,<br />
ich habe hier ener liste voll mit struct items und e3in array des types. nun moechte ich die items in der liste den array zuweisen.</p>
<p>-die liste besteht aus strcut items</p>
<p>list&lt; _Struct &gt; stack;<br />
_Struct array[ 5 ]; &lt;- dieses array ist in einer weiteren struct deklariert<br />
Tester tester;</p>
<p>wie komm ich nun in einer for()-schleife zu ziel?</p>
<p>for( ... ) {</p>
<p>tester.array[ i ] = stack. &lt;--- geht aber nicht</p>
<p>COMPILER:<br />
&quot;[C++ Error] MauMau.cpp(70): E2109 Not an allowed type&quot;</p>
<p>wieso geht des net und wie mach ichs beser?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/176647/wie-weise-ich-gepopte-list-items-einer-variable-zu</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 14:11:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/176647.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Mar 2007 10:42:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 10:42:13 GMT]]></title><description><![CDATA[<p>hi,<br />
ich habe hier ener liste voll mit struct items und e3in array des types. nun moechte ich die items in der liste den array zuweisen.</p>
<p>-die liste besteht aus strcut items</p>
<p>list&lt; _Struct &gt; stack;<br />
_Struct array[ 5 ]; &lt;- dieses array ist in einer weiteren struct deklariert<br />
Tester tester;</p>
<p>wie komm ich nun in einer for()-schleife zu ziel?</p>
<p>for( ... ) {</p>
<p>tester.array[ i ] = stack. &lt;--- geht aber nicht</p>
<p>COMPILER:<br />
&quot;[C++ Error] MauMau.cpp(70): E2109 Not an allowed type&quot;</p>
<p>wieso geht des net und wie mach ichs beser?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251031</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 23 Mar 2007 10:42:13 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 11:04:27 GMT]]></title><description><![CDATA[<p>Kannst du mal bitte etwas mehr zeigen als ein paar unzusammenhängende Fragmente?</p>
<p>(allgemein - list&lt;&gt;s bieten keinen Direktzugriff per Index. Aber du kannst per stack.front() das erste und per stack.back() das letzte Element deiner Liste herausgreifen (um alle Elemente zu bekommen, mußt du mit einem Iterator sequenziell durchlaufen))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251043</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 23 Mar 2007 11:04:27 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 11:21:39 GMT]]></title><description><![CDATA[<p>Hallo Tobi,</p>
<p>Deine Frage scheint mir etwas ungenau formuliert. Ich vermute mal Du hast in etwa so eine Struktur</p>
<pre><code class="language-cpp">struct Struct
{
    int m_dummy; // egal
};

struct Tester
{
    static int const array_size = 5;
    Struct m_array[array_size];
};
</code></pre>
<p>und eine std::list&lt; Struct &gt;, die in das m_array eines Tester-Objekts kopiert werden sollen. Das geht mit einer for-Schleife so:</p>
<pre><code class="language-cpp">list&lt; Struct &gt; stack;  
    // stack füllen 
    Tester tester;
    list&lt; Struct &gt;::iterator j = stack.begin();
    for( int i=0; i&lt;Tester::array_size &amp;&amp; j != stack.end(); ++i, ++j )
    {
        tester.m_array[i] = *j;
    }
</code></pre>
<p>eleganter aber mit einem std::copy - also</p>
<pre><code class="language-cpp">assert( stack.size() &lt;= Tester::array_size ); // erst prüfen, dass array nicht überläuft
    copy( stack.begin(), stack.end(), tester.m_array );
</code></pre>
<p>Für letzteres braucht man die Includes &lt;algorithm&gt; und &lt;cassert&gt;.</p>
<p>Oder - noch 'ne Nummer eleganter; man kann auch eine Zuweisung daraus machen.</p>
<pre><code class="language-cpp">struct Tester
{
    template&lt; typename C &gt;  // C: Container-Klasse
    Tester&amp; operator=( const C&amp; c )
    {
        using namespace std;
        assert( c.size() &lt;= Tester::array_size ); // erst prüfen, dass array nicht überläuft
        copy( c.begin(), c.end(), m_array );
        return *this;
    }

    static int const array_size = 5;
    Struct m_array[array_size];
};

// -- Aufruf; (Variablen s.o.)
    tester = stack;
</code></pre>
<p>Das bitte aber nur, wenn m_array der einzige (bzw. fast der einzige) Member in der struct Tester ist.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251053</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Fri, 23 Mar 2007 11:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 11:36:21 GMT]]></title><description><![CDATA[<p>hmm... also irgendwie komm ich net mit klar... *brett vorm kop -.-*<br />
ich schick euch mal den quelltext, ist ja noch nicht so viel.</p>
<p>es soll nen kleines MauMau spiel werden... im mom sollen nur die karten init werdenund in eine liste geladen werden... und dann auf 4spieler verteilt werden.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;list&gt;
#include &lt;conio&gt;
#include &lt;ctime&gt;
    using namespace std;

#pragma hdrstop
#pragma argsused

#define MAX_CARDS 32

struct Cards {

    char _color[8];
    char _value[4];
    int color;
    int value;
};

struct Player {

    Cards _cards[ 5 ];  // 5 cards for each player
    int wins;
    int lose;
};

void intCards( Cards stack[ MAX_CARDS ], list&lt; Cards &gt; con ) {

    bool isInStack;
    char *_color[] = { &quot;Heart&quot;, &quot;Caro&quot;, &quot;Pike&quot;, &quot;Cross&quot; };
    char *_value[] = { &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;, &quot;J&quot;, &quot;Q&quot;, &quot;K&quot;, &quot;A&quot; };

    for( int i = 0; i &lt; MAX_CARDS; i++ ) {

        do {

            stack[ i ].color = rand() % 4;
            stack[ i ].value = rand() % 8;

            isInStack = false;
            for( int j = 0; j &lt; i; j++ ) {

                if( ( stack[ j ].color == stack[ i ].color ) &amp;&amp;
                    ( stack[ j ].value == stack[ i ].value ) ) {

                    isInStack = true;

                }
            }
        } while( isInStack );
    }

    for( int i = 0; i &lt; MAX_CARDS; i++ ) {

        strcpy( stack[ i ]._color, _color[ stack[ i ].color ] );
        strcpy( stack[ i ]._value, _value[ stack[ i ].value ] );
        con.push_back( stack[ i ] );
    }
}

void givePlayerCards( Player player[ 4 ], list&lt; Cards &gt; con ) {

    Cards current;

    // hand Player1 cards
    for( int i = 0; i &lt; 5; i++ ) {

        current = con.back();
   //    player[ 0 ]._cards[ i ] = current;
        strcpy( player[ 0 ]._cards[ i ]._color, current._color );
        strcpy( player[ 0 ]._cards[ i ]._value, current._value );
        con.pop_back();
    }

/*    // hand Player2 cards
    for( int i = 0; i &lt; 5; i++ ) {

        strcpy( player[ 1 ]._cards[ i ]._color, stack[ i+5 ]._color );
        strcpy( player[ 1 ]._cards[ i ]._value, stack[ i+5 ]._value );
    }

    // hand Player3 cards
    for( int i = 0; i &lt; 5; i++ ) {

        strcpy( player[ 2 ]._cards[ i ]._color, stack[ i+10 ]._color );
        strcpy( player[ 2 ]._cards[ i ]._value, stack[ i+10 ]._value );
    }

    // hand Player4 cards
    for( int i = 0; i &lt; 5; i++ ) {

        strcpy( player[ 3 ]._cards[ i ]._color, stack[ i+15 ]._color );
        strcpy( player[ 3 ]._cards[ i ]._value, stack[ i+15 ]._value );
    }
*/
}

int main(int argc, char* argv[]) {

    srand( time( 0 ) );
    Cards stack[ 32 ];
    Player player[ 4 ];
    list&lt; Cards &gt; con; // contains all 32 created cards
    list&lt; Cards &gt;::iterator oti;
    list&lt; Cards &gt; cemetery; // contains all played cards

    intCards( stack, con );

    for( int i = 0; i &lt; MAX_CARDS; i++ ) {

        cout &lt;&lt; setw( 2 ) &lt;&lt; i+1 &lt;&lt; &quot;.Card:   &quot; &lt;&lt; setw( 5 ) &lt;&lt; left &lt;&lt; stack[ i ]._color
             &lt;&lt; &quot; &quot; &lt;&lt; setw( 2 ) &lt;&lt; right &lt;&lt; stack[ i ]._value &lt;&lt; endl;
    }
    givePlayerCards( player, con );

    cout &lt;&lt; &quot;\n=================================\n&quot; &lt;&lt; endl;
    for( int i = 0; i &lt; 5; i++ ) {

        cout &lt;&lt; player[ 0 ]._cards[ i ]._color &lt;&lt; &quot; &quot;
             &lt;&lt; player[ 0 ]._cards[ i ]._value &lt;&lt; endl;
    }
    getchar();
    return 0;
}
</code></pre>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251060</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251060</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 23 Mar 2007 11:36:21 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 12:04:06 GMT]]></title><description><![CDATA[<p>Erstmal solltest du die Möglichkeit bedenken, daß ein Spieler auch mehr oder weniger als 5 Karten bekommen kann (d.h. anstelle des Arrays <code>Cards _cards[5];</code> ist eine list&lt;Cards&gt; besser geeignet).</p>
<p>Zweitens kannst du die Karte als eine einzelne Zahl (0..31) speichern und für die Ausgabe auseinandernehmen:</p>
<pre><code class="language-cpp">struct Card
{
  int value;
};
ostream&amp; operator&lt;&lt;(ostream&amp; fout,Card c)
{
  static const string Color[] = {&quot;Karo&quot;,&quot;Herz&quot;,&quot;Pik&quot;,&quot;Kreuz&quot;};
  static const string Wert[] = {&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,&quot;Bube&quot;,&quot;Dame&quot;,&quot;König&quot;,&quot;As&quot;};
  fout&lt;&lt;Color[c.value%4]&lt;&lt;&quot; &quot;&lt;&lt;Wert[c.value/4];
  return fout;
}
</code></pre>
<p>Drittens: Schau dir mal random_shuffle() an.</p>
<p>Viertens: Wo genau liegt dein Problem?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251072</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 23 Mar 2007 12:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 12:08:42 GMT]]></title><description><![CDATA[<blockquote>
<p>Viertens: Wo genau liegt dein Problem?</p>
</blockquote>
<p>ich kann kein MauMau xD.</p>
<p>Trotzdem erstmal danke, Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251078</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 23 Mar 2007 12:08:42 GMT</pubDate></item><item><title><![CDATA[Reply to wie weise ich gepopte list items einer variable zu ? on Fri, 23 Mar 2007 13:21:42 GMT]]></title><description><![CDATA[<p>T0bi schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void intCards( Cards stack[ MAX_CARDS ], list&lt; Cards &gt; con ) {
// ..
</code></pre>
</blockquote>
<p>Der Parameter 'con' muss hier als 'list&lt; Cards &gt;&amp; con' also per Referenz übergeben werden, damit man in der Routine initCards auf die Variable in main zugreift und nicht auf dessen Kopie.</p>
<p>T0bi schrieb:</p>
<blockquote>
<p>ich kann kein MauMau xD.</p>
</blockquote>
<p>Schlag nach bei <a href="http://de.wikipedia.org/wiki/Mau-Mau" rel="nofollow">Wiki</a>.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1251125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1251125</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Fri, 23 Mar 2007 13:21:42 GMT</pubDate></item></channel></rss>