<?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[strings per index zuweisen]]></title><description><![CDATA[<p>Moin,</p>
<p>eine wahrscheinlich für euch einfache Frage zu einem &quot;Array&quot;:</p>
<p>Ich hab mehrere Strings die sich namentlich nur durch den letzten Index unterscheiden. Nacheinander sollen diese Strings dem String test zugeordnet werden in der for-Schleife - wie muss ich das richtig deklarieren?</p>
<pre><code class="language-cpp">string Sel1; 
string Sel2; 
string Sel3; 

for(int i=1; i&lt;=3; i++)
{
   string test = Sel[i]; 
}
</code></pre>
<p>Gruß<br />
Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274577/strings-per-index-zuweisen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 10:37:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274577.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Sep 2010 19:41:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 19:41:16 GMT]]></title><description><![CDATA[<p>Moin,</p>
<p>eine wahrscheinlich für euch einfache Frage zu einem &quot;Array&quot;:</p>
<p>Ich hab mehrere Strings die sich namentlich nur durch den letzten Index unterscheiden. Nacheinander sollen diese Strings dem String test zugeordnet werden in der for-Schleife - wie muss ich das richtig deklarieren?</p>
<pre><code class="language-cpp">string Sel1; 
string Sel2; 
string Sel3; 

for(int i=1; i&lt;=3; i++)
{
   string test = Sel[i]; 
}
</code></pre>
<p>Gruß<br />
Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958716</guid><dc:creator><![CDATA[Felix Halbritter]]></dc:creator><pubDate>Tue, 28 Sep 2010 19:41:16 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 19:45:41 GMT]]></title><description><![CDATA[<p>Das geht so nicht und das ist auch kein Array von Strings. Wenn du eines willst, dann musst du schon eines machen:</p>
<pre><code class="language-cpp">string Sel[3]; // &lt;- Das ist ein Array!

for(int i=1; i&lt;=3; i++)
{
   string test = Sel[i];
}
</code></pre>
<p>Dazu sei erwähnt, dass du dir auch mal die Standardcontainer anschauen solltest. Siehe dazu <a href="http://www.cplusplus.com/reference/" rel="nofollow">hier</a>. <code>boost::array</code> , respektive <code>std::tr1::array</code> wären allerdings auch Alternativen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958717</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 28 Sep 2010 19:45:41 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 19:47:06 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

int main()
{
	std::string sel[3]; // Array mit 3 Elementen

	sel[0] = &quot;Sel Nr. 1&quot;; // Werte zuweisen; Erstes Element hat den Index 0
	sel[1] = &quot;Sel Nr. 2&quot;;
	sel[2] = &quot;Sel Nr. 3&quot;;

	for (int i = 0; i &lt; 3; ++i)
	{
		std::string test = sel[i];

		std::cout &lt;&lt; test &lt;&lt; std::endl;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1958719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958719</guid><dc:creator><![CDATA[,,,,,,]]></dc:creator><pubDate>Tue, 28 Sep 2010 19:47:06 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 19:50:57 GMT]]></title><description><![CDATA[<p>Danke für deine Antwort drakon.</p>
<p>Geht das auch mit den Strings über deren Namen??? Also wenn es kein Array sondern wirklich drei Strings Sel1-3 sind?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958721</guid><dc:creator><![CDATA[Felix Halbritter]]></dc:creator><pubDate>Tue, 28 Sep 2010 19:50:57 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 20:16:31 GMT]]></title><description><![CDATA[<p>Nein, eher nicht. Man kann etwas mit makros basteln, dass dem ein wenig näher kommt, aber wirklich dynamisch wird das nie werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958734</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 28 Sep 2010 20:16:31 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Tue, 28 Sep 2010 20:36:59 GMT]]></title><description><![CDATA[<p>Das höchste der Gefühle ist, sie vorher in ein Array zu quetschen. Etwa</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

int main() {
  std::string s1 = &quot;foo&quot;;
  std::string s2 = &quot;bar&quot;;
  std::string s3 = &quot;baz&quot;;

  std::string *a[3] = { &amp;s1, &amp;s2, &amp;s3 };

  for(int i = 0; i &lt; 3; ++i) {
    std::cout &lt;&lt; *a[i] &lt;&lt; '\n';
  }
}
</code></pre>
<p>Über den Sinn einer solchen Konstruktion kann man aber streiten.</p>
<p>Die Namen der Variablen, so wie du sie in den Quellcode schreibst, sind zur Laufzeit nicht mehr vorhanden, also kannst du auch nicht darüber auf sie zugreifen. So was geht generell nur in Skriptsprachen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958741</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Tue, 28 Sep 2010 20:36:59 GMT</pubDate></item><item><title><![CDATA[Reply to strings per index zuweisen on Wed, 29 Sep 2010 06:54:28 GMT]]></title><description><![CDATA[<p>Es geht auch über Namen, allerdings nicht explizit über Variablennamen. std::map&lt;std::string, std::string&gt; bietet die Möglichkeit, strings unter bestimmten Namen abzulegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958806</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Wed, 29 Sep 2010 06:54:28 GMT</pubDate></item></channel></rss>