<?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[arrayfrage]]></title><description><![CDATA[<p>hallo!</p>
<p>ich habe ein problem mit einem array, ich möchte darin einen wert aendern, dabei stürzt das programm ab. wo liegt mein fehler?</p>
<p>mein code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;stdlib.h&gt;

using namespace std;

/*char *field [] = { &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;,
&quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot; };
*/
int main () {
    char *field [] = {&quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;,
    &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;};
    int koord_x;
    cin&gt;&gt;koord_x;
    int koord_y;
    cin&gt;&gt;koord_y;
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
    delete (field[koord_x][koord_y]);
    field[koord_x][koord_y] = 'l';
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
    int x;
    x = 0;
    int y;
    y = 0;
    while (x != 8) {
          while ( y != 8) {
          cout&lt;&lt;field[x][y];
          y++;
          }
          cout&lt;&lt;endl;
    y = 0;
    x++;
}
cin.get();
cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/185041/arrayfrage</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 01:18:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/185041.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Jun 2007 12:22:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:22:03 GMT]]></title><description><![CDATA[<p>hallo!</p>
<p>ich habe ein problem mit einem array, ich möchte darin einen wert aendern, dabei stürzt das programm ab. wo liegt mein fehler?</p>
<p>mein code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;stdlib.h&gt;

using namespace std;

/*char *field [] = { &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;,
&quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot; };
*/
int main () {
    char *field [] = {&quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;,
    &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;, &quot;xxxxxxxx&quot;};
    int koord_x;
    cin&gt;&gt;koord_x;
    int koord_y;
    cin&gt;&gt;koord_y;
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
    delete (field[koord_x][koord_y]);
    field[koord_x][koord_y] = 'l';
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
    int x;
    x = 0;
    int y;
    y = 0;
    while (x != 8) {
          while ( y != 8) {
          cout&lt;&lt;field[x][y];
          y++;
          }
          cout&lt;&lt;endl;
    y = 0;
    x++;
}
cin.get();
cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1310634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310634</guid><dc:creator><![CDATA[a question]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:26:04 GMT]]></title><description><![CDATA[<p>lösch die Zeile mit dem delete...nur was Du per new angefordert hast, kannst Du mit delete freigeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310637</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310637</guid><dc:creator><![CDATA[~Airdamn]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:26:04 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:28:42 GMT]]></title><description><![CDATA[<p>das problem besteht immer noch, nach der ausgabe des wertes stürzt das programm mit undefiniertem verhalten ab...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310645</guid><dc:creator><![CDATA[a question again]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:28:42 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:35:26 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich sehe 2 Alternativen für Dich:<br />
A) (zu der würde ich dringend raten) Du nutzt einen vernünftigen Container</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

int main () {
    vector&lt;string&gt; field;
    for(size_t i=0; i&lt;8; ++i) field.push_back(&quot;xxxxxxxx&quot;);

    size_t koord_x; // soll doch sowieso &gt;= 0 sein, oder ? Dann sag es dem Compiler mit einem size_t ;)
    cin&gt;&gt;koord_x;   // Sicherheitsabfrage, ob Input gültig war solltest Du noch machen
    size_t koord_y;
    cin&gt;&gt;koord_y;
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
    field[koord_x][koord_y] = 'l'; // Wenn Du Überschreiben willst, brauchst Du nicht vorher zu löschen
    cout&lt;&lt;field[koord_x][koord_y]&lt;&lt;endl;
// Hiernach kommt einiges an &quot;Kraut&amp;Rüben&quot;-Code, de IMO noch überarbeitet werden sollte
</code></pre>
<p>Wenn Du wirklich etwas aus eine String entfernen möchtest (z.B. &quot;Simon2&quot; -&gt; &quot;Sion2&quot;), solltest Du Dir die erase()-Funktion von string ansehen.<br />
Insgesamt eine gute (wenn auch manchmal etwas knappe) InfoQuelle: <a href="http://www.cppreference.com" rel="nofollow">www.cppreference.com</a> .</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="B)"
      alt="😎"
    /> Du arbeitest Dich gründlich in das Thema &quot;Pointer/Arrays/const&quot; ein.<br />
(&quot;delete&quot; ist KERNfalsch in dem Zusammenhang!)</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310649</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:35:26 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:32:49 GMT]]></title><description><![CDATA[<p>das problem ist nicht nur das delete, da deine elemente vom typ const char* sind. somit kannst du nichts darauf ändern..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310650</guid><dc:creator><![CDATA[pinta]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:38:09 GMT]]></title><description><![CDATA[<p>der code ist nur testweise...</p>
<p>gut, dann mal noch 2 fragen</p>
<p>1. was macht vector&lt;string&gt; ? wie darf man sich das vorstellen? macht das gleich ein virtuelles 2d feld?<br />
2. was ist size_t für ein typ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310654</guid><dc:creator><![CDATA[fragenersteller]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:38:09 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:41:56 GMT]]></title><description><![CDATA[<p>fragenersteller schrieb:</p>
<blockquote>
<p>der code ist nur testweise...</p>
<p>gut, dann mal noch 2 fragen</p>
<p>1. was macht vector&lt;string&gt; ? wie darf man sich das vorstellen? macht das gleich ein virtuelles 2d feld?<br />
2. was ist size_t für ein typ?</p>
</blockquote>
<p>2 Gegenfragen<br />
1. Hast Du irgendein Tutorial zur Hand ? Es ist im Netz und zahllosen Büchern bereits alles Wichtige und Gute dazu geschrieben worden, so dass ich mich jetzt nicht 2 Stunden hinsetze, um es nochmal einzutippen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>2. Was ist &quot;ein virtuelles 2d feld&quot; ? ... ich bin mir aber ziemlich sicher, dass es weder mein noch Dein Code erzeugt (Deiner versucht ein Array auf char-Pointer zu nutzen, meiner einen vector von strings).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310658</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:45:58 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Einen vector&lt;typ&gt; kann man sich wie eine liste von objekten vom typ &lt;typ&gt;<br />
vorstellen, man kann hinzufügen, entfernen usw...</p>
<p>In deinem fall wären das 8 char[8] variablen, die du dann indizieren kannst...<br />
mit den ersten arrayklammern [] wird dein Objekt indiziert, mit den zweiten<br />
der char in dem char*.</p>
<p>size_t ist ein</p>
<p>typedef unsigned long size_t;</p>
<p>der zum definieren von groessen in zeichenketten oder speicherbereichen<br />
benutzt wird... kannst die ihn aber auch einfach als unsigned long vorstellen...</p>
<p>Gruß,<br />
benth</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310662</guid><dc:creator><![CDATA[benth]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:45:58 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:51:06 GMT]]></title><description><![CDATA[<p>benth schrieb:</p>
<blockquote>
<p>...char[8] ...</p>
</blockquote>
<p>Wieso nicht string ?</p>
<p>benth schrieb:</p>
<blockquote>
<p>...<br />
size_t ist ein</p>
<p>typedef unsigned long size_t;<br />
...</p>
</blockquote>
<p>MÖP falsch ! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
Der Standard legt nicht fest, wie size_t implementiert wird, sondern nur, dass er &quot;für Adress-Indizierungen geeignet&quot; sein muss. Auf anderen Systemen ist size_t bestimmt anders definiert (wobei IIRC nicht einmal sichergestellt ist, dass size_t aus einem anderen Datentype &quot;besteht&quot;, sondern theoretisch ein ganz eigener Datentyp sein kann).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310667</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:51:06 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:53:45 GMT]]></title><description><![CDATA[<p>Ich hatte das jetzt auf ANSI-C bezogen,<br />
du hast aber recht, der typ kann auch ne andre definition haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310673</guid><dc:creator><![CDATA[benth]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:53:45 GMT</pubDate></item><item><title><![CDATA[Reply to arrayfrage on Thu, 21 Jun 2007 12:59:35 GMT]]></title><description><![CDATA[<p>schreibe in den while schleifen statt &quot;!=8&quot; eine &quot;!= 7&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310681</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Thu, 21 Jun 2007 12:59:35 GMT</pubDate></item></channel></rss>