<?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[int in string umwandeln - Problem und Lösung]]></title><description><![CDATA[<p>Hallo,<br />
ich bin C++ Anfänger.<br />
Ich versuche mich im Programmieren und hatte zuletzt Probleme int-Werte als string auszugeben.<br />
Nach Suche in Google habe ich ein paar Lösungen gefunden wie <a href="http://www.cplusplus.com/reference/string/to_string/" rel="nofollow">http://www.cplusplus.com/reference/string/to_string/</a>.<br />
Leider funktioniert das bei mir nicht. -&gt; Ubuntu -&gt; Programm Geany, Qt<br />
Vielleicht sind meine Bibliotheken falsch eingestellt.</p>
<p>Ich habe jetzt erstmal eine eigene Funktion geschrieben, die für mich das Problem löst. Vielleicht kann mir jemand sagen, wie ich die Datei speichern muss damit ich sie als Precompiler-Befehl in meine nächsten Programm einbinden kann.</p>
<p>Kann mir ansonsten jemand sagen ob das erstmal eine gute Lösung ist?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

char itoc(int);
string itos(int);

int main(){
  int i=312354;
  string s=itos(i);
  cout&lt;&lt;s;
  return 0;
}

char itoc(int i){   //Konvertiere einzelne Ziffer in char
 char c;
 if(i==1){c='1';}
 else if(i==2){c='2';}
 else if(i==3){c='3';}
 else if(i==4){c='4';}
 else if(i==5){c='5';}
 else if(i==6){c='6';}
 else if(i==7){c='7';}
 else if(i==8){c='8';}
 else if(i==9){c='9';}
 else if(i==0){c='0';}
 return c;
}

string itos(int i){  //Konvertiere int in string
 string s;
 char c;
 while(i&gt;9){
  int r=i%10;
  int t=i/10;
  i=t;
  c=itoc(r);
  s=c+s;
 }
 if(i&lt;10&amp;&amp;i!=0){
  c=itoc(i);
  s=c+s;
 }
 return s;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/337207/int-in-string-umwandeln-problem-und-lösung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 08:25:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/337207.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Mar 2016 09:32:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to int in string umwandeln - Problem und Lösung on Wed, 16 Mar 2016 09:32:25 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich bin C++ Anfänger.<br />
Ich versuche mich im Programmieren und hatte zuletzt Probleme int-Werte als string auszugeben.<br />
Nach Suche in Google habe ich ein paar Lösungen gefunden wie <a href="http://www.cplusplus.com/reference/string/to_string/" rel="nofollow">http://www.cplusplus.com/reference/string/to_string/</a>.<br />
Leider funktioniert das bei mir nicht. -&gt; Ubuntu -&gt; Programm Geany, Qt<br />
Vielleicht sind meine Bibliotheken falsch eingestellt.</p>
<p>Ich habe jetzt erstmal eine eigene Funktion geschrieben, die für mich das Problem löst. Vielleicht kann mir jemand sagen, wie ich die Datei speichern muss damit ich sie als Precompiler-Befehl in meine nächsten Programm einbinden kann.</p>
<p>Kann mir ansonsten jemand sagen ob das erstmal eine gute Lösung ist?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

char itoc(int);
string itos(int);

int main(){
  int i=312354;
  string s=itos(i);
  cout&lt;&lt;s;
  return 0;
}

char itoc(int i){   //Konvertiere einzelne Ziffer in char
 char c;
 if(i==1){c='1';}
 else if(i==2){c='2';}
 else if(i==3){c='3';}
 else if(i==4){c='4';}
 else if(i==5){c='5';}
 else if(i==6){c='6';}
 else if(i==7){c='7';}
 else if(i==8){c='8';}
 else if(i==9){c='9';}
 else if(i==0){c='0';}
 return c;
}

string itos(int i){  //Konvertiere int in string
 string s;
 char c;
 while(i&gt;9){
  int r=i%10;
  int t=i/10;
  i=t;
  c=itoc(r);
  s=c+s;
 }
 if(i&lt;10&amp;&amp;i!=0){
  c=itoc(i);
  s=c+s;
 }
 return s;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2490500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2490500</guid><dc:creator><![CDATA[sigmar87]]></dc:creator><pubDate>Wed, 16 Mar 2016 09:32:25 GMT</pubDate></item><item><title><![CDATA[Reply to int in string umwandeln - Problem und Lösung on Wed, 16 Mar 2016 09:43:51 GMT]]></title><description><![CDATA[<p>sigmar87 schrieb:</p>
<blockquote>
<p>Leider funktioniert das bei mir nicht. -&gt; Ubuntu -&gt; Programm Geany, Qt</p>
</blockquote>
<p>Eine sehr aussagekräftige Beschreibung.</p>
<p>Vermutlich liefert der Compiler eine Fehlermeldung. Lösung: richtige Standardversion auswählen. Mit g++ --std=c++11 ... sollte es gehen. Ich würde aber g++ --std=c++1z ... probieren (das wäre der sich aktuell in Entwicklung befindende Standard) oder zumindest g++ --std=c++14 ... (das wäre der aktuelle Standard).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2490504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2490504</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 16 Mar 2016 09:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to int in string umwandeln - Problem und Lösung on Wed, 16 Mar 2016 09:51:36 GMT]]></title><description><![CDATA[<p>In einer qmake einfach</p>
<pre><code>CONFIG += c++11
</code></pre>
<p>hinzufügen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2490507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2490507</guid><dc:creator><![CDATA[key]]></dc:creator><pubDate>Wed, 16 Mar 2016 09:51:36 GMT</pubDate></item><item><title><![CDATA[Reply to int in string umwandeln - Problem und Lösung on Wed, 16 Mar 2016 11:01:13 GMT]]></title><description><![CDATA[<p>sigmar87 schrieb:</p>
<blockquote>
<p>und hatte zuletzt Probleme int-Werte als string auszugeben.</p>
</blockquote>
<p>hast Du schon das versucht?</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int main(){
  int i=312354;
  cout&lt;&lt;i;
  return 0;
}
</code></pre>
<p>Umwandeln in einen String ginge so:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main(){
  int i=312354;
  string s = to_string(i);
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2490520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2490520</guid><dc:creator><![CDATA[Kenner von C++]]></dc:creator><pubDate>Wed, 16 Mar 2016 11:01:13 GMT</pubDate></item><item><title><![CDATA[Reply to int in string umwandeln - Problem und Lösung on Sat, 19 Mar 2016 12:56:50 GMT]]></title><description><![CDATA[<p>Bin selbst Anfänger und hab mir so geholfen:</p>
<p>Stringstream initialisieren<br />
Mit dem Operator &lt;&lt; deinen INT einfließen lassen<br />
Anschließend in einem String umwandeln mit .str()</p>
<p>Google mal stringstream</p>
<p>Der Code ist wirklich klein und easy.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2490863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2490863</guid><dc:creator><![CDATA[Caccamolla]]></dc:creator><pubDate>Sat, 19 Mar 2016 12:56:50 GMT</pubDate></item></channel></rss>