<?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[std::map Binär in Datei schreiben]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich würde gerne eine std::map (binär) in eine Datei schreiben, so wie sie im Arbeitsspeicher steht, damit sie für weitere Programmdurchläufe aufgerufen werden kann.</p>
<p>Das Problem ist, das es mit dem fstream nicht funktioniert (nach einem Tutorial aus dem Netz):</p>
<pre><code class="language-cpp">map&lt;KeyType,list&lt;X&gt; &gt; database;

/* database wird befüllt */

fstream f1;
f1.open(&quot;database.bin&quot;,ios::out|ios::binary);
f1.write(&amp;database,sizeof(database));
f1.close();
</code></pre>
<p>Ergibt einen Compiler-Fehler, da die Methode &quot;write&quot; wohl den ersten Parameter vom Typ &quot;char[]&quot; erwartet (fstream scheint also nur für das Speichern von Daten in form von Text zu funktionieren).</p>
<p>Gibt es überhaupt eine Möglichkeit die map database irgendwie eins zu eins auf die Festplatte zu bekommen, um sie bei späteren Aufrufen dem Programm wieder zur verfügung zu stellen?</p>
<p>danke schonmal.<br />
foxx</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/294232/std-map-binär-in-datei-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 23:30:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/294232.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 20 Oct 2011 13:26:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 13:26:29 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich würde gerne eine std::map (binär) in eine Datei schreiben, so wie sie im Arbeitsspeicher steht, damit sie für weitere Programmdurchläufe aufgerufen werden kann.</p>
<p>Das Problem ist, das es mit dem fstream nicht funktioniert (nach einem Tutorial aus dem Netz):</p>
<pre><code class="language-cpp">map&lt;KeyType,list&lt;X&gt; &gt; database;

/* database wird befüllt */

fstream f1;
f1.open(&quot;database.bin&quot;,ios::out|ios::binary);
f1.write(&amp;database,sizeof(database));
f1.close();
</code></pre>
<p>Ergibt einen Compiler-Fehler, da die Methode &quot;write&quot; wohl den ersten Parameter vom Typ &quot;char[]&quot; erwartet (fstream scheint also nur für das Speichern von Daten in form von Text zu funktionieren).</p>
<p>Gibt es überhaupt eine Möglichkeit die map database irgendwie eins zu eins auf die Festplatte zu bekommen, um sie bei späteren Aufrufen dem Programm wieder zur verfügung zu stellen?</p>
<p>danke schonmal.<br />
foxx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133707</guid><dc:creator><![CDATA[zachery_foxx]]></dc:creator><pubDate>Thu, 20 Oct 2011 13:26:29 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 13:32:57 GMT]]></title><description><![CDATA[<p>normalerweise castet man den ersten parameter von write nach char*</p>
<pre><code class="language-cpp">f1.write(reinterpret_cast&lt;char*&gt;(&amp;database), sizeof(database));
</code></pre>
<p>aber ist keine gute idee stl container binär zu speichern, jedenfalls nicht so wie du meinst</p>
<p>überleg mal was passiert wenn du eine klasse binär so speicherst die aber einen pointer inne hat der auf z.b. ein array zeigt...<br />
wird da das array mitgespeichert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133709</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 20 Oct 2011 13:32:57 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 14:14:30 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>erstmal danke für die schnelle Antwort.<br />
nein, es ist vermutlich keine gute Idee.<br />
Ich hatte gehofft, das es dafür vielleicht andere Standardmittel gibt.</p>
<p>Ich hab jetzt nochmal recherchiert und es scheint in der boost eine lib zu geben, die das macht (Stichwort Serialization: <a href="http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/index.html</a>).</p>
<p>Ich hab jetzt das aus der Dokumentation nicht ganz verstanden, aber die scheint genau das zu machen, dass alles, was mit der zu speichernden Klasse/Container zusammenhängt auf die Platte schreibt (also werden auch evtl. Pointer dereferenziert und mit gespeichert).</p>
<p>Ich hoffe, das daraus was wird <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Edit:<br />
Achso ich kenne die Klassen, die in der Map verwendet werden (selbst geschrieben) und sie enthalten keine Pointer <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>
<p>Gruß<br />
foxx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133725</guid><dc:creator><![CDATA[zachery_foxx]]></dc:creator><pubDate>Thu, 20 Oct 2011 14:14:30 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 14:24:58 GMT]]></title><description><![CDATA[<p>aber die Map verwendet Pointer</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133732</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Thu, 20 Oct 2011 14:24:58 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 14:29:07 GMT]]></title><description><![CDATA[<p>Also kann man die std::map nicht mit Standardmitteln komplett auf die Platte schreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133735</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133735</guid><dc:creator><![CDATA[zachery_foxx]]></dc:creator><pubDate>Thu, 20 Oct 2011 14:29:07 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 14:31:10 GMT]]></title><description><![CDATA[<p>doch, aber es gibt keine WriteMap Funktion. Sowas müsstest du dir selbst bauen.</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133738</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Thu, 20 Oct 2011 14:31:10 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 15:56:35 GMT]]></title><description><![CDATA[<p>und dmait bräuchtest du auch eine read funktion sonst kriegstes nichtmehr zurück, aber da du das selbst schreiben musst, sind dir alle freiheiten gegeben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133767</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 20 Oct 2011 15:56:35 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Thu, 20 Oct 2011 16:00:33 GMT]]></title><description><![CDATA[<p>Übrigens: Gibt es einen Grund warum du</p>
<pre><code class="language-cpp">map&lt;KeyType,list&lt;X&gt; &gt;
</code></pre>
<p>anstatt</p>
<pre><code class="language-cpp">multimap&lt;KeyType, X&gt;
</code></pre>
<p>verwendest?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133769</guid><dc:creator><![CDATA[mazal]]></dc:creator><pubDate>Thu, 20 Oct 2011 16:00:33 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Fri, 21 Oct 2011 07:24:51 GMT]]></title><description><![CDATA[<p>Ich dachte bisher die std::map kann zu einem Key immer nur eine Value speichern. Da es aber vorkommen kann (und wahrscheinlich ist), das zu einem Key mehrere Values (Mehrere <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f635.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--dizzy_face"
      title="X)"
      alt="😵"
    /> gespeichert werden, verwende ich hier eine std::list um auch Dopplungen zuzulassen.</p>
<p>Edit: uups, überlesen, dass es &quot;multimap&quot; heißt... werde das mal in der Referenz nachschlagen, danke <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/2133916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133916</guid><dc:creator><![CDATA[zachery_foxx]]></dc:creator><pubDate>Fri, 21 Oct 2011 07:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to std::map Binär in Datei schreiben on Fri, 21 Oct 2011 07:24:43 GMT]]></title><description><![CDATA[<p>Deshalb eine multimap.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2133917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2133917</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Fri, 21 Oct 2011 07:24:43 GMT</pubDate></item></channel></rss>