<?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[sprintf mit %s bringt programm zum absturz]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin Anfänger in C++ und stehe grade vor einem Problemchen.<br />
Ich verwende in meinem Programm ein String mit dem namen &quot;file&quot;<br />
und lasse dann vom User einen Dateinamen bestimmen.<br />
Danach tritt dann das Problem auf und zwar in dieser Zeile:<br />
sprintf(buffer, &quot;GET %s&quot;, file);</p>
<p>Hier noch einmal der Code:</p>
<pre><code class="language-cpp">std::string file;
std::cout &lt;&lt; &quot;Bitte Dateinamen angeben: &quot;;
std::cin &gt;&gt; file;
char buffer[8192];
sprintf(buffer, &quot;GET %s&quot;, file);
</code></pre>
<p>Ich denke einfach mal das Problem liegt daran, dass die Variable buffer von einem anderen Typ ist wie die Variable file, aber wie behebe ich nun das Problem?</p>
<p>Gruß, Thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/202567/sprintf-mit-s-bringt-programm-zum-absturz</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 18:02:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/202567.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Jan 2008 02:01:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to sprintf mit %s bringt programm zum absturz on Sun, 13 Jan 2008 02:01:24 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin Anfänger in C++ und stehe grade vor einem Problemchen.<br />
Ich verwende in meinem Programm ein String mit dem namen &quot;file&quot;<br />
und lasse dann vom User einen Dateinamen bestimmen.<br />
Danach tritt dann das Problem auf und zwar in dieser Zeile:<br />
sprintf(buffer, &quot;GET %s&quot;, file);</p>
<p>Hier noch einmal der Code:</p>
<pre><code class="language-cpp">std::string file;
std::cout &lt;&lt; &quot;Bitte Dateinamen angeben: &quot;;
std::cin &gt;&gt; file;
char buffer[8192];
sprintf(buffer, &quot;GET %s&quot;, file);
</code></pre>
<p>Ich denke einfach mal das Problem liegt daran, dass die Variable buffer von einem anderen Typ ist wie die Variable file, aber wie behebe ich nun das Problem?</p>
<p>Gruß, Thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1435718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1435718</guid><dc:creator><![CDATA[XanaX]]></dc:creator><pubDate>Sun, 13 Jan 2008 02:01:24 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf mit %s bringt programm zum absturz on Sun, 13 Jan 2008 06:54:28 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-275.html" rel="nofollow">Unix-Tom</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-1.html" rel="nofollow">MFC (Visual C++)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1435727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1435727</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 13 Jan 2008 06:54:28 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf mit %s bringt programm zum absturz on Sun, 13 Jan 2008 09:40:03 GMT]]></title><description><![CDATA[<p>Du kannst natürlich keine C-Funktion (sprintf) mit einem C++-String verwenden. Also entweder den C++-String in einen C-String umwandeln:</p>
<pre><code class="language-cpp">std::string file; 
std::cout &lt;&lt; &quot;Bitte Dateinamen angeben: &quot;; 
std::cin &gt;&gt; file; 
char buffer[8192]; 
sprintf(buffer, &quot;GET %s&quot;, file.c_str());
</code></pre>
<p>Oder gleich vollständig C++</p>
<pre><code class="language-cpp">std::string file; 
std::cout &lt;&lt; &quot;Bitte Dateinamen angeben: &quot;; 
std::cin &gt;&gt; file; 
std::stringstream buffer;
buffer &lt;&lt; &quot;GET &quot; &lt;&lt; file;
</code></pre>
<p>Wenn du dann den C++-String brauchst must du dir diesen mit buffer.str(); holen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1435753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1435753</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sun, 13 Jan 2008 09:40:03 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf mit %s bringt programm zum absturz on Sun, 13 Jan 2008 09:49:26 GMT]]></title><description><![CDATA[<p>Hier stand Müll,weil nicht richtig gelesen -.-<br />
Sorry.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1435757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1435757</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sun, 13 Jan 2008 09:49:26 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf mit %s bringt programm zum absturz on Sun, 13 Jan 2008 09:56:15 GMT]]></title><description><![CDATA[<p>buffer ist ja ein std::stringstream, kein std::string.</p>
<p>EDIT: Dies bzog sich auf Scorchers Müll <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1435758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1435758</guid><dc:creator><![CDATA[Don06]]></dc:creator><pubDate>Sun, 13 Jan 2008 09:56:15 GMT</pubDate></item></channel></rss>