<?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[Daten aus einem string mit sscanf lesen]]></title><description><![CDATA[<p>Hallo,<br />
Ich lese aus einer Datei mehrere Datensätze aus und speichere diese in einem String. Aus diesem will ich nun verschiedene Werte auslesen. Der String ist so aufgebaut:</p>
<p>&quot;&lt; x = 128 y = 480 img = img/A.png type = passable &gt;&quot;</p>
<p>Ich verwende sscanf_s um die Daten auszulesen:</p>
<pre><code>char img[64];
char ObjecType[64];
sscanf_s(lines[i].c_str(),
&quot;&lt; x = %i y = %i img = %s type = %s&gt;&quot;,&amp;x,&amp;y,img,ObjectType);
</code></pre>
<p>Allerdings unterbricht das Programm, wenn ich die Funktion ausführe. VS sagt der Fehler würde an dieser Stelle auftreten aber ich weiß nicht was ich falsch mache. Ich habe mich schon eine Menge im Internet umgeguckt aber nirgendwo wird genau erklärt wie ich das Problem Lösen kann.<br />
Kann mir hier jemand helfen?</p>
<p>mfg,<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/321100/daten-aus-einem-string-mit-sscanf-lesen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 14:06:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321100.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Oct 2013 15:29:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 15:29:51 GMT]]></title><description><![CDATA[<p>Hallo,<br />
Ich lese aus einer Datei mehrere Datensätze aus und speichere diese in einem String. Aus diesem will ich nun verschiedene Werte auslesen. Der String ist so aufgebaut:</p>
<p>&quot;&lt; x = 128 y = 480 img = img/A.png type = passable &gt;&quot;</p>
<p>Ich verwende sscanf_s um die Daten auszulesen:</p>
<pre><code>char img[64];
char ObjecType[64];
sscanf_s(lines[i].c_str(),
&quot;&lt; x = %i y = %i img = %s type = %s&gt;&quot;,&amp;x,&amp;y,img,ObjectType);
</code></pre>
<p>Allerdings unterbricht das Programm, wenn ich die Funktion ausführe. VS sagt der Fehler würde an dieser Stelle auftreten aber ich weiß nicht was ich falsch mache. Ich habe mich schon eine Menge im Internet umgeguckt aber nirgendwo wird genau erklärt wie ich das Problem Lösen kann.<br />
Kann mir hier jemand helfen?</p>
<p>mfg,<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362414</guid><dc:creator><![CDATA[Agreon]]></dc:creator><pubDate>Wed, 23 Oct 2013 15:29:51 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 15:40:39 GMT]]></title><description><![CDATA[<p>sscanf ist nicht für C++ strings geeignet.<br />
Verwende istringstream, den kannste so wie cin verwenden.</p>
<p>Edit: Am stri.g liegts nicht, aber Tipp stimmt trotzdem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362421</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Wed, 23 Oct 2013 15:40:39 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 15:53:35 GMT]]></title><description><![CDATA[<p>Könntest du mir vielleicht einen Lösungsvorschlag zeigen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362429</guid><dc:creator><![CDATA[Agreon]]></dc:creator><pubDate>Wed, 23 Oct 2013 15:53:35 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 16:42:51 GMT]]></title><description><![CDATA[<p>Ich weiß nicht ob es nötig ist, aber ein Leerzeichen vor dem &gt; schadet nicht.<br />
X und Y sin auch int?</p>
<p>Bei %i sei noch angemerkt, das bei führenden Nullen die Zahl als Oktaldarstellung interpretiert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362453</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Wed, 23 Oct 2013 16:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 16:59:17 GMT]]></title><description><![CDATA[<p>Du verwendest <code>sscanf_s</code> falsch. <code>%s</code> will <code>char *</code> und zudem die Buffergröße als <code>unsigned</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362459</guid><dc:creator><![CDATA[EinGast]]></dc:creator><pubDate>Wed, 23 Oct 2013 16:59:17 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 18:23:49 GMT]]></title><description><![CDATA[<p>Habe es meiner Meinung nach relativ unsauber geläst, aber hey! Es funktioniert ! <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>
<pre><code>istringstream iss(lines[i]);
iss &gt;&gt; temp &gt;&gt; temp &gt;&gt; temp &gt;&gt; stringX &gt;&gt; temp &gt;&gt; temp &gt;&gt; stringY &gt;&gt; temp &gt;&gt; temp &gt;&gt; img &gt;&gt; temp &gt;&gt; temp &gt;&gt; ObjectType;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2362492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362492</guid><dc:creator><![CDATA[Agreon]]></dc:creator><pubDate>Wed, 23 Oct 2013 18:23:49 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 19:09:23 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>sscanf ist nicht für C++ strings geeignet.<br />
Verwende istringstream, den kannste so wie cin verwenden.</p>
<p>Edit: Am stri.g liegts nicht, aber Tipp stimmt trotzdem.</p>
</blockquote>
<p>Was? Natürlich ist es das.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362505</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Wed, 23 Oct 2013 19:09:23 GMT</pubDate></item><item><title><![CDATA[Reply to Daten aus einem string mit sscanf lesen on Wed, 23 Oct 2013 19:59:07 GMT]]></title><description><![CDATA[<p>Ethon schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>sscanf ist nicht für C++ strings geeignet.<br />
Verwende istringstream, den kannste so wie cin verwenden.</p>
<p>Edit: Am stri.g liegts nicht, aber Tipp stimmt trotzdem.</p>
</blockquote>
<p>Was? Natürlich ist es das.</p>
</blockquote>
<p>Hab mir den Code nicht genau angesehen, ging einfach davon aus, dass er versuchte via sscanf in einen std::string einzulesen, was ja nicht geht.<br />
Habs im Edit ja auch korrigiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2362518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2362518</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Wed, 23 Oct 2013 19:59:07 GMT</pubDate></item></channel></rss>