<?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[[SOLVED] Kleines Problem mit std::fill]]></title><description><![CDATA[<p>Hallo, nach langer Abwesenheit melde ich mich zurück und hab auch gleich ein kleines Problemchen mitgebracht.</p>
<p>Ich versuche ein kleines Programm zu scchreiben welches einen Irrgarten erstellt aber scheitere schon derzeit daran das 2D-Array, welches ich dafür erstellt habe, zu befüllen. Während 'memset' super funktioniert und keine Probleme macht (compilen ok, ausführen fehlerlos), will 'std:fill' irgendwie nicht (compilen ok, ausführen Programm bricht ab).</p>
<p>So aber mal genug geschwafel hier ist mein kleines Code Beispiel.</p>
<pre><code>#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstring&gt;
#include &lt;ctime&gt;
#include &lt;algorithm&gt;

int main () // int argc, char* argv [])
{
	// creating maze array, for testing purposes of 10 width x 20 height
	int playfield [10][20] = {};

	// filling array with -1 for all cells
	// memset(&amp;playfield[0][0], -1, sizeof(playfield)); // funktioniert
	std::fill(&amp;playfield[0][0], &amp;playfield[0][0] + sizeof(playfield), -1);

	// initializing random generator, only needed once per runtime
	srand (time (NULL));

	for (int x = 0; x &lt; 10; x++)
	{
		for (int y = 0; y &lt; 20; y++)
		{
			std::cout &lt;&lt; playfield [x][y] &lt;&lt; &quot; &quot;;
		}
		std::cout &lt;&lt; std::endl;
	}

    return 0;
}
</code></pre>
<p>Vielen Dank schon mal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328917/solved-kleines-problem-mit-std-fill</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 06:35:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328917.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 31 Oct 2014 11:43:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 12:06:19 GMT]]></title><description><![CDATA[<p>Hallo, nach langer Abwesenheit melde ich mich zurück und hab auch gleich ein kleines Problemchen mitgebracht.</p>
<p>Ich versuche ein kleines Programm zu scchreiben welches einen Irrgarten erstellt aber scheitere schon derzeit daran das 2D-Array, welches ich dafür erstellt habe, zu befüllen. Während 'memset' super funktioniert und keine Probleme macht (compilen ok, ausführen fehlerlos), will 'std:fill' irgendwie nicht (compilen ok, ausführen Programm bricht ab).</p>
<p>So aber mal genug geschwafel hier ist mein kleines Code Beispiel.</p>
<pre><code>#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstring&gt;
#include &lt;ctime&gt;
#include &lt;algorithm&gt;

int main () // int argc, char* argv [])
{
	// creating maze array, for testing purposes of 10 width x 20 height
	int playfield [10][20] = {};

	// filling array with -1 for all cells
	// memset(&amp;playfield[0][0], -1, sizeof(playfield)); // funktioniert
	std::fill(&amp;playfield[0][0], &amp;playfield[0][0] + sizeof(playfield), -1);

	// initializing random generator, only needed once per runtime
	srand (time (NULL));

	for (int x = 0; x &lt; 10; x++)
	{
		for (int y = 0; y &lt; 20; y++)
		{
			std::cout &lt;&lt; playfield [x][y] &lt;&lt; &quot; &quot;;
		}
		std::cout &lt;&lt; std::endl;
	}

    return 0;
}
</code></pre>
<p>Vielen Dank schon mal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2425103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425103</guid><dc:creator><![CDATA[Videonauth]]></dc:creator><pubDate>Fri, 31 Oct 2014 12:06:19 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 11:49:29 GMT]]></title><description><![CDATA[<pre><code>&amp;playfield[0][0] + sizeof(playfield)/sizeof(playfield[0][0})
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2425104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425104</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 31 Oct 2014 11:49:29 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 11:59:08 GMT]]></title><description><![CDATA[<p>Warum doppelt initialisieren?</p>
<pre><code class="language-cpp">int playfield [10][20] = { -1 };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2425106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425106</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Fri, 31 Oct 2014 11:59:08 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 12:02:00 GMT]]></title><description><![CDATA[<p>Yuk! Mehrdimensionale Arrays... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Du musst halt eins hinter das letzte Element greifen:</p>
<pre><code class="language-cpp">std::fill(&amp;playfield[0][0], &amp;playfield[9][20], -1);
// oder
std::fill(&amp;playfield[0][0], &amp;playfield[10][0], -1);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2425108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425108</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 31 Oct 2014 12:02:00 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 12:13:48 GMT]]></title><description><![CDATA[<p>Th69 schrieb:</p>
<blockquote>
<p>Warum doppelt initialisieren?</p>
<pre><code class="language-cpp">int playfield [10][20] = { -1 };
</code></pre>
</blockquote>
<p>Weil das nur den allerersten Wert auf -1 setzt.</p>
<p>@ Volkart: Danke, das war der Casus Knacktus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2425109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425109</guid><dc:creator><![CDATA[Videonauth]]></dc:creator><pubDate>Fri, 31 Oct 2014 12:13:48 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Kleines Problem mit std::fill on Fri, 31 Oct 2014 14:22:04 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<pre><code>&amp;playfield[0][0] + sizeof(playfield)/sizeof(playfield[0][0})
</code></pre>
</blockquote>
<p>Der Grund, dass das so geht ist, dass sizeof die Größe in Bytes zurückgibt. Deswegen klappt das mit dem memset auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2425130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2425130</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 31 Oct 2014 14:22:04 GMT</pubDate></item></channel></rss>