<?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[Save and LOad System]]></title><description><![CDATA[<p>Hey leute ich habe ein Save und LOad system geschrieben bzw bin dabei und beim Load system habe ich nun einige Probleme, ich würde gerne die txt zeilenweiße auslesen und dann in eine Variable übergeben. Hier ist mein COde</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;

using namespace std;      //Prototypen
int status_save(char name[200],char herotyp[50],int health,int mana,int mindmg,int maxdmg,int defence,int level,
    int xp,int id);

void status();
int id_berechnen();
int laden();

int main()    //erste auf gerufene Funktion
{
int eing;
cout &lt;&lt;&quot;1 --&gt; Speichern&quot;&lt;&lt;&quot;\n&quot;;
cout &lt;&lt;&quot;2 --&gt; Laden&quot;&lt;&lt;&quot;\n&quot;;
cout &lt;&lt;&quot;ihre Wahl:&quot;;
cin &gt;&gt; eing;
switch(eing)
{
case 1 : status();
break;

case 2 : laden();
break;
};

}

void status()
{

 char name[200];    // Physische Eigenschaften werden erzeugt
    int health;
    int mana;
    int mindmg;
    int maxdmg;   // werden noch Pointer damit Ständig verfügbar !!
    int defence;
    char herotyp[50];
    int level;
    int xp;

    int id=1;
    health=100;    // standart werte zugewießen
    mana=25;
    mindmg=1;
    maxdmg=50;
    defence=75;
    xp=20;
    level=5;

    cout &lt;&lt;&quot;Spielename:&quot; ;
    cin.getline(name,200);   // Spieler NAme

    status_save(name,herotyp,health,mana,mindmg,maxdmg,defence,xp,level,id);
}

int status_save(char name[200],char herotyp[50],int health,int mana,int mindmg,int maxdmg,int defence,int level,
    int xp,int id)
{

   int berechnete_id=id_berechnen();
   cout &lt;&lt; &quot;Waehle einen Accountnamen &quot; &lt;&lt; flush;
   string file_name;
   getline(cin, file_name);
   CreateDirectory(&quot;Saves&quot;, NULL);
   file_name.insert(0, &quot;Saves\\&quot;);
   if (file_name.substr(file_name.length() - 4) != &quot;.sav&quot;)
    file_name += &quot;.sav&quot;;

    ofstream fout(file_name.c_str(), ios::app);
    cout &lt;&lt; &quot;Dein Account wird unter '&quot; &lt;&lt; file_name &lt;&lt; &quot;' gespeichert ...&quot; &lt;&lt; endl;
    fout &lt;&lt; berechnete_id;
    fout &lt;&lt; endl;
    fout &lt;&lt; name;
    fout &lt;&lt; endl;
    fout &lt;&lt;  herotyp;
    fout &lt;&lt; endl;
    fout &lt;&lt;  health;
    fout &lt;&lt; endl;
    fout &lt;&lt; mana;
    fout &lt;&lt; endl;
    fout &lt;&lt;  mindmg;
    fout &lt;&lt; endl;
    fout &lt;&lt; maxdmg;
    fout &lt;&lt; endl;
    fout &lt;&lt;  defence;
    fout &lt;&lt; endl;
    fout &lt;&lt;xp;
    fout &lt;&lt; endl;
    fout &lt;&lt; level;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;

fout.close();

}

int id_berechnen()   // Ganz WIchtig es muss einen ordner ID mit einer id.txt geben wo eine 0 drin steht !!!!!!
{

    ifstream file(&quot;ID\\id.txt&quot;);
    char line[100];
    file.get( line, 100);
    file.close();
    int value;
    value = atoi( line );
    value += 1;
    ofstream out ( &quot;ID\\id.txt&quot; );
    out &lt;&lt; value;
    out.close();
    return value;
}

int laden()
{

    string dateiname;

    DIR *dirHandle;
   struct dirent * dirEntry;

   dirHandle = opendir(&quot;Saves\\&quot;);
    if (dirHandle) {
   while (0 != (dirEntry = readdir(dirHandle))) {
   puts(dirEntry-&gt;d_name);
    }
   closedir(dirHandle);
    }
    cout &lt;&lt; &quot;Gib den Namen deines Saves ein, den du laden willst:&quot;;
    cin &gt;&gt; dateiname;
    cout &lt;&lt; &quot;Load '&quot; &lt;&lt; dateiname &lt;&lt; &quot;' ...\n&quot;;
    dateiname.insert(0, &quot;Saves\\&quot;);
    ifstream Load (dateiname.c_str(), ios::binary);

     string id;
     string buffer;
    string text;
     getline(Load, buffer);
     text += id + &quot;\n&quot;;
     cout &lt;&lt; text;
     Load.close();
}
</code></pre>
<p>Ich hoffe mir kann jemand helfen verbesserungs Vorschläge mit Hilfen immer willkommen !</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/185670/save-and-load-system</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 06:16:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/185670.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 29 Jun 2007 15:36:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 15:36:52 GMT]]></title><description><![CDATA[<p>Hey leute ich habe ein Save und LOad system geschrieben bzw bin dabei und beim Load system habe ich nun einige Probleme, ich würde gerne die txt zeilenweiße auslesen und dann in eine Variable übergeben. Hier ist mein COde</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;

using namespace std;      //Prototypen
int status_save(char name[200],char herotyp[50],int health,int mana,int mindmg,int maxdmg,int defence,int level,
    int xp,int id);

void status();
int id_berechnen();
int laden();

int main()    //erste auf gerufene Funktion
{
int eing;
cout &lt;&lt;&quot;1 --&gt; Speichern&quot;&lt;&lt;&quot;\n&quot;;
cout &lt;&lt;&quot;2 --&gt; Laden&quot;&lt;&lt;&quot;\n&quot;;
cout &lt;&lt;&quot;ihre Wahl:&quot;;
cin &gt;&gt; eing;
switch(eing)
{
case 1 : status();
break;

case 2 : laden();
break;
};

}

void status()
{

 char name[200];    // Physische Eigenschaften werden erzeugt
    int health;
    int mana;
    int mindmg;
    int maxdmg;   // werden noch Pointer damit Ständig verfügbar !!
    int defence;
    char herotyp[50];
    int level;
    int xp;

    int id=1;
    health=100;    // standart werte zugewießen
    mana=25;
    mindmg=1;
    maxdmg=50;
    defence=75;
    xp=20;
    level=5;

    cout &lt;&lt;&quot;Spielename:&quot; ;
    cin.getline(name,200);   // Spieler NAme

    status_save(name,herotyp,health,mana,mindmg,maxdmg,defence,xp,level,id);
}

int status_save(char name[200],char herotyp[50],int health,int mana,int mindmg,int maxdmg,int defence,int level,
    int xp,int id)
{

   int berechnete_id=id_berechnen();
   cout &lt;&lt; &quot;Waehle einen Accountnamen &quot; &lt;&lt; flush;
   string file_name;
   getline(cin, file_name);
   CreateDirectory(&quot;Saves&quot;, NULL);
   file_name.insert(0, &quot;Saves\\&quot;);
   if (file_name.substr(file_name.length() - 4) != &quot;.sav&quot;)
    file_name += &quot;.sav&quot;;

    ofstream fout(file_name.c_str(), ios::app);
    cout &lt;&lt; &quot;Dein Account wird unter '&quot; &lt;&lt; file_name &lt;&lt; &quot;' gespeichert ...&quot; &lt;&lt; endl;
    fout &lt;&lt; berechnete_id;
    fout &lt;&lt; endl;
    fout &lt;&lt; name;
    fout &lt;&lt; endl;
    fout &lt;&lt;  herotyp;
    fout &lt;&lt; endl;
    fout &lt;&lt;  health;
    fout &lt;&lt; endl;
    fout &lt;&lt; mana;
    fout &lt;&lt; endl;
    fout &lt;&lt;  mindmg;
    fout &lt;&lt; endl;
    fout &lt;&lt; maxdmg;
    fout &lt;&lt; endl;
    fout &lt;&lt;  defence;
    fout &lt;&lt; endl;
    fout &lt;&lt;xp;
    fout &lt;&lt; endl;
    fout &lt;&lt; level;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;
    fout &lt;&lt; endl;

fout.close();

}

int id_berechnen()   // Ganz WIchtig es muss einen ordner ID mit einer id.txt geben wo eine 0 drin steht !!!!!!
{

    ifstream file(&quot;ID\\id.txt&quot;);
    char line[100];
    file.get( line, 100);
    file.close();
    int value;
    value = atoi( line );
    value += 1;
    ofstream out ( &quot;ID\\id.txt&quot; );
    out &lt;&lt; value;
    out.close();
    return value;
}

int laden()
{

    string dateiname;

    DIR *dirHandle;
   struct dirent * dirEntry;

   dirHandle = opendir(&quot;Saves\\&quot;);
    if (dirHandle) {
   while (0 != (dirEntry = readdir(dirHandle))) {
   puts(dirEntry-&gt;d_name);
    }
   closedir(dirHandle);
    }
    cout &lt;&lt; &quot;Gib den Namen deines Saves ein, den du laden willst:&quot;;
    cin &gt;&gt; dateiname;
    cout &lt;&lt; &quot;Load '&quot; &lt;&lt; dateiname &lt;&lt; &quot;' ...\n&quot;;
    dateiname.insert(0, &quot;Saves\\&quot;);
    ifstream Load (dateiname.c_str(), ios::binary);

     string id;
     string buffer;
    string text;
     getline(Load, buffer);
     text += id + &quot;\n&quot;;
     cout &lt;&lt; text;
     Load.close();
}
</code></pre>
<p>Ich hoffe mir kann jemand helfen verbesserungs Vorschläge mit Hilfen immer willkommen !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315105</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Fri, 29 Jun 2007 15:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 15:42:50 GMT]]></title><description><![CDATA[<p>Grauenhaftes (=kein) design...<br />
Wie lautet denn deine Aufgabenstellung!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315113</guid><dc:creator><![CDATA[kenner der dummköpfe]]></dc:creator><pubDate>Fri, 29 Jun 2007 15:42:50 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 15:53:09 GMT]]></title><description><![CDATA[<p>WIe aufgaben STellung ? Das mach ich Freiwillig <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="😃"
    /> FÜr ein Game ^^<br />
ALso ich hab versucht halt die Eigenschafen des Chars in ner Txt zu sichern und diese dann mit einem Load script in Variablen wieder laden aber ich habe Probleme mit dem Zeilenweiße auslesen , der letzde abschnitt befasst sich mit dem laden da möchte ich die erste Zeile laden wo die Id vermerkt ist aber er liest sie nicht aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315128</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Fri, 29 Jun 2007 15:53:09 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 15:57:27 GMT]]></title><description><![CDATA[<p>überleg dir lieber mal, wie du deine 'Chars' - ich nehme an du meinst Charaktere - im Programm repräsentierst. Welche Eigenschaften besitzen sie, welche Methoden benötigen sie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315136</guid><dc:creator><![CDATA[kenner der dummköpfe]]></dc:creator><pubDate>Fri, 29 Jun 2007 15:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 16:03:27 GMT]]></title><description><![CDATA[<p>Das habsch doch schon alles, ich versuchs zu erklären was die datei macht bzw machen soll :</p>
<p>int health;<br />
int mana;<br />
int mindmg;<br />
int maxdmg;<br />
int defence;<br />
char herotyp[50];<br />
int level;<br />
int xp;<br />
int id=1;</p>
<p>Das sind die sachen die Gesichert werden müssen das wird oben in der datei abgehandelt , da werden diese eigenschaften in ne Txt geschrieben.</p>
<p>im unterenTeil habe ich versucht ein Load QUellcode zu schreiben der diese Sachen wieder aus der txt ausliest und in variablen speichert aber es klappt nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315144</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Fri, 29 Jun 2007 16:03:27 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 16:07:58 GMT]]></title><description><![CDATA[<p>Schön aufgelistet, die Eigenschaften. Denen gibst du jetzt vernünftige Namen und packst sie in eine Klasse.</p>
<p>BTW: &quot;es klappt nicht&quot; ist keine Fehlerbeschreibung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315151</guid><dc:creator><![CDATA[kenner der dummköpfe]]></dc:creator><pubDate>Fri, 29 Jun 2007 16:07:58 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Sat, 30 Jun 2007 10:52:02 GMT]]></title><description><![CDATA[<p>*heul* das hab ich doch alles nur gemacht das mit dem Int war nur ein Beispiel COde damit net jeder gleich mein gesamtes game hat <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
<p>struct sPlayer<br />
{<br />
std::string name;<br />
std::string HeroTyp;<br />
int health;<br />
int mana;<br />
int maxdmg;<br />
int mindmg;<br />
int defence;<br />
int level;<br />
int xp;<br />
float geld;<br />
};</p>
<p>besser ? Ich will doch nur diese Werte in ne Txt speichern können und auch wieder laden können... ich weiß das ich es oben umständlich gemacht hab</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315158</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Sat, 30 Jun 2007 10:52:02 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 16:23:45 GMT]]></title><description><![CDATA[<p>Na endlich!</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;

using namespace std;

int main( ) {

    sPlayer player;

    ofstream ofile( &quot;foo.sav&quot;, ios::binary )
    ofile.write( &amp;player, sizeof( sPlayer ) );
    ofile.close( );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1315166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315166</guid><dc:creator><![CDATA[kenner der dummköpfe]]></dc:creator><pubDate>Fri, 29 Jun 2007 16:23:45 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Sat, 30 Jun 2007 10:52:45 GMT]]></title><description><![CDATA[<p>juhu danke xD , hab das oben voll Umständlich gemacht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315170</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315170</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Sat, 30 Jun 2007 10:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 18:35:02 GMT]]></title><description><![CDATA[<p>kenner der dummköpfe schrieb:</p>
<blockquote>
<p>Na endlich!</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;

using namespace std;

int main( ) {

    sPlayer player;

    ofstream ofile( &quot;foo.sav&quot;, ios::binary )
    ofile.write( &amp;player, sizeof( sPlayer ) );
    ofile.close( );
}
</code></pre>
</blockquote>
<p>Ich wage zu bezweifeln, dass ein write() mit std::strings so klappt (höchstens vielleicht ganz kurzen)....</p>
<p>Mein Vorschlag: Sinnvolles Protokoll definieren und damit &quot;serialisieren&quot; (im Javasinne).</p>
<p>Also sowas wie:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

struct sPlayer {
   std::string name;
   int health;
   float geld;
}; 

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; ost, sPlayer const&amp; p) {
      return ost &lt;&lt; p.name &lt;&lt; &quot; &quot; &lt;&lt; p.health &lt;&lt; &quot; &quot; &lt;&lt; p.geld &lt;&lt; &quot;\n&quot;;
}

std::istream&amp; operator&gt;&gt;(std::istream&amp; ist, sPlayer&amp; p) {
   ist &gt;&gt; p.name;
   ist &gt;&gt; p.health;
   ist &gt;&gt; p.geld;
   return ist;
}

using namespace std;

int main( ) {
   sPlayer player;

   ofstream ofile( &quot;foo.sav&quot;);
   ofile &lt;&lt; player;
   ofile.close( );

   ifstream ifile( &quot;foo.sav&quot;);
   ifile &gt;&gt; player;
   return 0;   
}
</code></pre>
<p>Vorteil: Egal ob File, Konsole, Netzwerk, .... mit jedem Stream funktioniert's.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315234</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 29 Jun 2007 18:35:02 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 20:49:01 GMT]]></title><description><![CDATA[<p>Edit: eigener Thread dazu <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="😉"
    /><br />
<a href="http://c-plusplus.net/forum/viewtopic-var-t-is-185691.html" rel="nofollow">http://c-plusplus.net/forum/viewtopic-var-t-is-185691.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315237</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315237</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 29 Jun 2007 20:49:01 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 18:52:36 GMT]]></title><description><![CDATA[<p>Öhm das Loaden möchte ich so machen das man sich den Account aussuchen kann, ich habe es jetzt soweit</p>
<pre><code>string dateiname;

    DIR *dirHandle;
   struct dirent * dirEntry;

   dirHandle = opendir(&quot;Saves\\&quot;);
    if (dirHandle) {
   while (0 != (dirEntry = readdir(dirHandle))) {
   puts(dirEntry-&gt;d_name);
    }
   closedir(dirHandle);
    }
    cout &lt;&lt; &quot;Gib den Namen deines Saves ein, den du laden willst:&quot;;
    cin &gt;&gt; dateiname;
    cout &lt;&lt; &quot;Load '&quot; &lt;&lt; dateiname &lt;&lt; &quot;' ...\n&quot;;
    dateiname.insert(0, &quot;Saves\\&quot;);
    ifstream Load (dateiname.c_str(), ios::binary);
</code></pre>
<p>ist dass richtig und wie bau ich dann da das loaden von dir ein ohne das es Probleme gibt ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315247</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Fri, 29 Jun 2007 18:52:36 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 19:36:28 GMT]]></title><description><![CDATA[<p>Toa schrieb:</p>
<blockquote>
<p>...</p>
<pre><code>...
    DIR 
...
   struct dirent ...
   dirHandle = opendir(...
   readdir(dirHandle))) {
...
   closedir(dirHandle);
...
</code></pre>
</blockquote>
<p>Also damit bewegst Du Dich außerhalb des Standards (was nicht schlimm und vermutlich sogar notwendig ist) ... damit kenne ich mich nicht aus.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315266</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 29 Jun 2007 19:36:28 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 20:24:26 GMT]]></title><description><![CDATA[<p>So fertig <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>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;dirent.h&gt;
using namespace std;

int save();
int id_berechnen();
int load();

struct sPlayer
{
std::string name;
std::string HeroTyp;
int health;
int mana;
int maxdmg;
int mindmg;
int defence;
int level;
int xp;
float geld;
};

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; ost, sPlayer const&amp; p) {
      return ost &lt;&lt; p.name &lt;&lt; &quot; &quot; &lt;&lt; p.health &lt;&lt; &quot; &quot; &lt;&lt; p.geld &lt;&lt; &quot; &quot;  &lt;&lt; p.HeroTyp &lt;&lt; &quot; &quot; &lt;&lt; p.mana &lt;&lt; &quot; &quot; &lt;&lt; p.maxdmg &lt;&lt; &quot; &quot; &lt;&lt;  p.mindmg &lt;&lt; &quot; &quot; &lt;&lt; p.defence &lt;&lt; &quot; &quot; &lt;&lt; p.level &lt;&lt; &quot; &quot; &lt;&lt;p.level &lt;&lt; &quot; &quot; &lt;&lt; p.xp &lt;&lt;&quot;\n&quot;;
}

std::istream&amp; operator&gt;&gt;(std::istream&amp; ist, sPlayer&amp; p) {
   ist &gt;&gt; p.name;
   ist &gt;&gt; p.health;
   ist &gt;&gt; p.geld;
   ist &gt;&gt; p.HeroTyp;
   ist &gt;&gt; p.mana;
   ist &gt;&gt; p.maxdmg;
   ist &gt;&gt; p.mindmg;
   ist &gt;&gt; p.defence;
   ist &gt;&gt; p.level;
   ist &gt;&gt; p.xp;
   return ist;
}

int id_berechnen()   // Ganz WIchtig es muss einen ordner ID mit einer id.txt geben wo eine 0 drin steht !!!!!!
{

    ifstream file(&quot;ID\\id.txt&quot;);
    char line[100];
    file.get( line, 100);
    file.close();
    int value;
    value = atoi( line );
    value += 1;
    ofstream out ( &quot;ID\\id.txt&quot; );
    out &lt;&lt; value;
    out.close();
    return value;
}

int save()
{

   int berechnete_id=id_berechnen();
   cout &lt;&lt; &quot;Waehle einen Accountnamen:&quot; &lt;&lt; flush;
   string file_name;
   getline(cin, file_name);
   CreateDirectory(&quot;Saves&quot;, NULL);
   file_name.insert(0, &quot;Saves\\&quot;);
   if (file_name.substr(file_name.length() - 4) != &quot;.sav&quot;)
   file_name += &quot;.sav&quot;;

    sPlayer player;
    ofstream ofile(file_name.c_str(), ios::app);
    ofile &lt;&lt; berechnete_id;
    ofile &lt;&lt; endl;
    ofile &lt;&lt; player;
    cout &lt;&lt; &quot;Dein Account wird unter '&quot; &lt;&lt; file_name &lt;&lt; &quot;' gespeichert ...&quot; &lt;&lt; &quot;\n&quot;&lt;&lt; endl;
    system(&quot;pause&quot;);
    system(&quot;cls&quot;);
    ofile.close();
}

int load()
{

    string dateiname;

    DIR *dirHandle;
    struct dirent * dirEntry;

    dirHandle = opendir(&quot;Saves\\&quot;);
    if (dirHandle) {
    while (0 != (dirEntry = readdir(dirHandle))) {
    puts(dirEntry-&gt;d_name);
    }
    closedir(dirHandle);
    }
    cout &lt;&lt; &quot;Gib den Namen deines Saves ein, den du laden willst:&quot;;
    cin &gt;&gt; dateiname;
    cout &lt;&lt; &quot;Load '&quot; &lt;&lt; dateiname &lt;&lt; &quot;' ...\n&quot;;
    dateiname.insert(0, &quot;Saves\\&quot;);
    sPlayer player;
    ifstream Load (dateiname.c_str(), ios::binary);
    Load &gt;&gt; player;
    Load.close();
}
</code></pre>
<p>Glaubst du das klappt so , weil wenn ich das Compilier kommt :</p>
<p>C:\Programme\CodeBlocks\lib\libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'<br />
collect2: ld returned 1 exit status<br />
Process terminated with status 1 (0 minutes, 3 seconds)</p>
<p>mh... und so kann ich die daten aus der Struktur in die Txt packen und wenn ich dann auf LOad zugreif sind sie wieder so in der Struktur geladen ?</p>
<p>Edit :</p>
<p>Ist es Besser wenn ich es so schreibe ?</p>
<pre><code>int Laden()
{
	// Datei zum Lesen öffnen und Spielestand laden
	cout &lt;&lt; &quot;\nLade Charakter...\n&quot;;
	ifstream Load (&quot;.&quot;, ios::binary);
        Load.read ((char*) &amp;wPlayer.Abenteuerpunkte, sizeof (wPlayer.Abenteuerpunkte));
	Load.read ((char*) &amp;wPlayer.name, sizeof (wPlayer.name));
	Load.read ((char*) &amp;wPlayer.HeroTyp, sizeof (wPlayer.HeroTyp));
	Load.read ((char*) &amp;wPlayer.health, sizeof (wPlayer.health));
	Load.read ((char*) &amp;wPlayer.mana, sizeof (wPlayer.mana));
	Load.read ((char*) &amp;wPlayer.maxdmg, sizeof (wPlayer.maxdmg));
	Load.read ((char*) &amp;wPlayer.mindmg, sizeof (wPlayer.mindmg));
	Load.read ((char*) &amp;wPlayer.defence, sizeof (wPlayer.defence));
	Load.read ((char*) &amp;wPlayer.level, sizeof (wPlayer.level));
	Load.read ((char*) &amp;wPlayer.xp, sizeof (wPlayer.xp));
	Load.read ((char*) &amp;wPlayer.geld, sizeof (wPlayer.geld));

	// Datei schließen
	Load.close ();

	return true;
}

int Speichern()
{
	// Datei zum Schreiben öffnen 
	cout &lt;&lt; &quot;\nSpeicher Charakter...\n&quot;;
	ofstream Save(&quot;&quot;, ios::binary);
	Save.write ((char*) &amp;wPlayer.name, sizeof (wPlayer.name));
	Save.write ((char*) &amp;wPlayer.HeroTyp, sizeof (wPlayer.HeroTyp));
	Save.write ((char*) &amp;wPlayer.health, sizeof (wPlayer.health));
	Save.write ((char*) &amp;wPlayer.mana, sizeof (wPlayer.mana));
	Save.write ((char*) &amp;wPlayer.maxdmg, sizeof (wPlayer.maxdmg));
	Save.write ((char*) &amp;wPlayer.mindmg, sizeof (wPlayer.mindmg));
	Save.write ((char*) &amp;wPlayer.defence, sizeof (wPlayer.defence));
	Save.write ((char*) &amp;wPlayer.level, sizeof (wPlayer.level));
	Save.write ((char*) &amp;wPlayer.xp, sizeof (wPlayer.xp));
	Save.write ((char*) &amp;wPlayer.geld, sizeof (wPlayer.geld));

    // Datei schließen
	Save.close ();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1315274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315274</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Fri, 29 Jun 2007 20:24:26 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Fri, 29 Jun 2007 20:51:55 GMT]]></title><description><![CDATA[<p>Toa schrieb:</p>
<blockquote>
<p>...<br />
Glaubst du das klappt so , weil wenn ich das Compilier kommt :...</p>
</blockquote>
<p>Kleiner Tipp: Schreibe nicht so, wie Du sprichst ! Denke daran, dass ich keine Betonungen mithöre.<br />
Ich brauchte 3 Anläufe, bis ich verstanden hab, was Du damit meinst. Du klebst ier zwei Sätze zu einem zusammen, sparst ein Fragezeichen (dauerte schon, bis ich begriff, dass Du hier eine Frage stellst) und einen Halbsatz &quot;Ich bin mir nicht sicher, ...&quot;.</p>
<p>OK, zum Thema: Dein &quot;Compiler&quot; (genauergesagt: Der Teil, der &quot;Linker&quot; genannt wird) will wissen, wo Dein Programm anfangen soll und erwartet deswegen eine &quot;WinMain&quot;-Funktion. Ist wieder windowsspezifisch (der Standard hat dafür die Funktion main()), weswegen ich Dir nicht genau sagen kann, wie Du das machst. Schau Dir einfach nochmal die Beispiele bei Deiner Entwicklungsumgebung (oder hier im Windows-unterforum) an.</p>
<p>Toa schrieb:</p>
<blockquote>
<p>...<br />
Ist es Besser wenn ich es so schreibe ?<br />
...</p>
</blockquote>
<p>Kurz gesagt: Nein !<br />
Hier schreibst Du &quot;direkt binär&quot; aus dem Speicher ins File. Was erstmal gut klingt, geht bei komplexeren Datentypen (wie z.B. std::string) schnell in die Hose, weil die selbst Daten &quot;auslagern&quot; und organisieren. Diese &quot;ausgelagerten Daten&quot; erwischt man dann nicht mit. Besser ist es, jeden Datentypen selbst seine &quot;Serialisierung&quot; (sprich: Die Form, in der er abgelegt werden möchte) bestimmen zu lassen und das machen die operator&lt;&lt;() und ..&gt;&gt;() für viele Typen schon gut und korrekt.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315311</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 29 Jun 2007 20:51:55 GMT</pubDate></item><item><title><![CDATA[Reply to Save and LOad System on Sat, 30 Jun 2007 09:32:59 GMT]]></title><description><![CDATA[<p>OKay habe ich soweit verstanden.Habe alles jetzt in eine Klasse geschrieben und ich denke es müsste klappen. Will mich noch mal bei dir bedanken und an meiner Forenschreibweiße werde ich arbeiten <sup>.</sup></p>
<p>MFG Toa</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1315462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1315462</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Sat, 30 Jun 2007 09:32:59 GMT</pubDate></item></channel></rss>