<?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[Object auslesen.]]></title><description><![CDATA[<p>Ich Speicher ein paar Objekte in einer file.<br />
Das schaut so aus</p>
<p>PictureBegin<br />
CIRCLE (255/255/0) 5 5 (100,100) 30<br />
LINE (255/0/0) 5 10 (100,100) (200,200)<br />
POINT (255/0/0) 0 (100,100)<br />
TEXT (0/0/0) 10 30 (20,40) 0 Test<br />
CIRCLE (255/255/0) 5 5 (100,100) 30<br />
PictureEnd</p>
<p>Nun möchte ich das wieder einlesen. Aber das funktioniert nicht. Ich weiß auch warum aber nicht geht. Aber ich komm nicht auf die Lösung.</p>
<p>Ich versuche mal meine Vorgehensweise am POINT darzustellen.</p>
<pre><code class="language-cpp">In Datei Schreibfunktion
void Point::write(ostream&amp; strm) const
{
   strm &lt;&lt; &quot;   POINT &quot;&lt;&lt; &quot;(&quot; &lt;&lt;(int)color.getRed() &lt;&lt; &quot;/&quot; &lt;&lt; (int)color.getGreen() &lt;&lt; &quot;/&quot; &lt;&lt; (int)color.getBlue() &lt;&lt; &quot;) &quot; &lt;&lt; style &lt;&lt; &quot; &quot; &lt;&lt; xy &lt;&lt; endl;
}
Aus Datei lese Funktion.
void Point::read(istream&amp; strm)
{
  int red,green,blue,style;
  strm &gt;&gt; red &gt;&gt; green &gt;&gt; blue &gt;&gt; style &gt;&gt; xy;
  this-&gt;style=(POINTSTYLE)style;
  Color c(red,green,blue);
  setColor(c);	 
}
</code></pre>
<p>Der strm der read funktion passt ja nicht weil da Zeichen wie ()/ drin sind. Oder irre ich mich da?</p>
<p>Hier noch meine Load Function. Die funktioniert soweit recht gut bis auf das sie noch nix läd.</p>
<pre><code class="language-cpp">Shape&amp; Picture::load(char* file)
{
    // Datei oeffnen
    ifstream load;
    load.open(file, ios::in);

    if (!load.good())//Pruefen ob sich Datei oeffnen laesst
    {
      cerr &lt;&lt; &quot;Datei -&quot;&lt;&lt;file&lt;&lt;&quot;- kann nicht geoeffnet werden&quot; &lt;&lt; endl &lt;&lt;endl;
      return *this;
    }

    //String mit \0 fuellen
    char saveDatei[1000];
    for (int i=0; i&lt;1000; i++)
    {
      saveDatei[i]='\0';
    }
    //erstes Wort aus Datei lesen
    load &gt;&gt; saveDatei;
    if(!strcmp (saveDatei, &quot;PictureBegin&quot;) ==0 )//PrÃ¼fen ob in der Datei ein Picture
    {					//Objekt vorahnden ist
      cout &lt;&lt; &quot;Kein Bild in der Datei!&quot; &lt;&lt; endl;
      return *this;
    }
    while(!load.eof() )
    {
      if (strcmp (saveDatei, &quot;TEXT&quot;)==0)  //Nach &quot;Text&quot; suchen
      {
        printf(&quot;Habe TEXT gefunden\n&quot;);
		 //Text* te = new Text(Coord(20,40),0,10,30,Black,&quot;Test&quot;);
        //load &gt;&gt; *te;
        //this-&gt;add(te);
      }
      else if (strcmp (saveDatei, &quot;POINT&quot;)==0)  //Nach &quot;Point&quot; suchen
      {
		printf(&quot;Habe POINT gefunden\n&quot;);
       // Point* po = new Point(Coord(100,100),Red,CROSS);
       // load &gt;&gt; *po;
       // this-&gt;add(po);
      }
      else if (strcmp (saveDatei, &quot;LINE&quot;)==0)  //Nach &quot;Line&quot; suchen
      {
		printf(&quot;Habe LINE gefunden\n&quot;); 
      //  Line* li = new Line(Coord(100,100),Coord(200,200),Green,_LONG_DASH,10);
      //  load &gt;&gt; *li;
      //  this-&gt;add(li);
      }
      else if (strcmp (saveDatei, &quot;CIRCLE&quot;)==0)  //Nach &quot;Circle&quot; suchen
      {
		  printf(&quot;Habe CIRCLE gefunden\n&quot;); 
      //  Circle* ci = new Circle(Coord(100,100),30,Yellow,_LONG_DASH,5);
      //  load &gt;&gt; *ci;
      //  this-&gt;add(ci);
      }
      else if (strcmp (saveDatei, &quot;PictureBegin&quot;)==0)
      {
      	//Bild im BIld
       }
       //String mit \0 fuellen
       for (int i=0; i&lt;1000; i++)
       {
          saveDatei[i]='\0';
       }
       //Naechstes Wort laden
       load &gt;&gt; saveDatei;
    }

    load.close();

    return *this;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/149463/object-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 07:40:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149463.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Jun 2006 10:55:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Object auslesen. on Tue, 06 Jun 2006 10:55:01 GMT]]></title><description><![CDATA[<p>Ich Speicher ein paar Objekte in einer file.<br />
Das schaut so aus</p>
<p>PictureBegin<br />
CIRCLE (255/255/0) 5 5 (100,100) 30<br />
LINE (255/0/0) 5 10 (100,100) (200,200)<br />
POINT (255/0/0) 0 (100,100)<br />
TEXT (0/0/0) 10 30 (20,40) 0 Test<br />
CIRCLE (255/255/0) 5 5 (100,100) 30<br />
PictureEnd</p>
<p>Nun möchte ich das wieder einlesen. Aber das funktioniert nicht. Ich weiß auch warum aber nicht geht. Aber ich komm nicht auf die Lösung.</p>
<p>Ich versuche mal meine Vorgehensweise am POINT darzustellen.</p>
<pre><code class="language-cpp">In Datei Schreibfunktion
void Point::write(ostream&amp; strm) const
{
   strm &lt;&lt; &quot;   POINT &quot;&lt;&lt; &quot;(&quot; &lt;&lt;(int)color.getRed() &lt;&lt; &quot;/&quot; &lt;&lt; (int)color.getGreen() &lt;&lt; &quot;/&quot; &lt;&lt; (int)color.getBlue() &lt;&lt; &quot;) &quot; &lt;&lt; style &lt;&lt; &quot; &quot; &lt;&lt; xy &lt;&lt; endl;
}
Aus Datei lese Funktion.
void Point::read(istream&amp; strm)
{
  int red,green,blue,style;
  strm &gt;&gt; red &gt;&gt; green &gt;&gt; blue &gt;&gt; style &gt;&gt; xy;
  this-&gt;style=(POINTSTYLE)style;
  Color c(red,green,blue);
  setColor(c);	 
}
</code></pre>
<p>Der strm der read funktion passt ja nicht weil da Zeichen wie ()/ drin sind. Oder irre ich mich da?</p>
<p>Hier noch meine Load Function. Die funktioniert soweit recht gut bis auf das sie noch nix läd.</p>
<pre><code class="language-cpp">Shape&amp; Picture::load(char* file)
{
    // Datei oeffnen
    ifstream load;
    load.open(file, ios::in);

    if (!load.good())//Pruefen ob sich Datei oeffnen laesst
    {
      cerr &lt;&lt; &quot;Datei -&quot;&lt;&lt;file&lt;&lt;&quot;- kann nicht geoeffnet werden&quot; &lt;&lt; endl &lt;&lt;endl;
      return *this;
    }

    //String mit \0 fuellen
    char saveDatei[1000];
    for (int i=0; i&lt;1000; i++)
    {
      saveDatei[i]='\0';
    }
    //erstes Wort aus Datei lesen
    load &gt;&gt; saveDatei;
    if(!strcmp (saveDatei, &quot;PictureBegin&quot;) ==0 )//PrÃ¼fen ob in der Datei ein Picture
    {					//Objekt vorahnden ist
      cout &lt;&lt; &quot;Kein Bild in der Datei!&quot; &lt;&lt; endl;
      return *this;
    }
    while(!load.eof() )
    {
      if (strcmp (saveDatei, &quot;TEXT&quot;)==0)  //Nach &quot;Text&quot; suchen
      {
        printf(&quot;Habe TEXT gefunden\n&quot;);
		 //Text* te = new Text(Coord(20,40),0,10,30,Black,&quot;Test&quot;);
        //load &gt;&gt; *te;
        //this-&gt;add(te);
      }
      else if (strcmp (saveDatei, &quot;POINT&quot;)==0)  //Nach &quot;Point&quot; suchen
      {
		printf(&quot;Habe POINT gefunden\n&quot;);
       // Point* po = new Point(Coord(100,100),Red,CROSS);
       // load &gt;&gt; *po;
       // this-&gt;add(po);
      }
      else if (strcmp (saveDatei, &quot;LINE&quot;)==0)  //Nach &quot;Line&quot; suchen
      {
		printf(&quot;Habe LINE gefunden\n&quot;); 
      //  Line* li = new Line(Coord(100,100),Coord(200,200),Green,_LONG_DASH,10);
      //  load &gt;&gt; *li;
      //  this-&gt;add(li);
      }
      else if (strcmp (saveDatei, &quot;CIRCLE&quot;)==0)  //Nach &quot;Circle&quot; suchen
      {
		  printf(&quot;Habe CIRCLE gefunden\n&quot;); 
      //  Circle* ci = new Circle(Coord(100,100),30,Yellow,_LONG_DASH,5);
      //  load &gt;&gt; *ci;
      //  this-&gt;add(ci);
      }
      else if (strcmp (saveDatei, &quot;PictureBegin&quot;)==0)
      {
      	//Bild im BIld
       }
       //String mit \0 fuellen
       for (int i=0; i&lt;1000; i++)
       {
          saveDatei[i]='\0';
       }
       //Naechstes Wort laden
       load &gt;&gt; saveDatei;
    }

    load.close();

    return *this;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1072361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072361</guid><dc:creator><![CDATA[Z3D]]></dc:creator><pubDate>Tue, 06 Jun 2006 10:55:01 GMT</pubDate></item><item><title><![CDATA[Reply to Object auslesen. on Tue, 06 Jun 2006 11:07:40 GMT]]></title><description><![CDATA[<p>Hi,</p>
<blockquote>
<p>Der strm der read funktion passt ja nicht weil da Zeichen wie ()/ drin sind. Oder irre ich mich da?</p>
</blockquote>
<p>ja, so ist es. Außerdem würde ich dir zu einem einheitlichen Trennzeichen raten, etwa # oder $.</p>
<p>MfG</p>
<p>GPC</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1072373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072373</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:07:40 GMT</pubDate></item><item><title><![CDATA[Reply to Object auslesen. on Tue, 06 Jun 2006 11:08:09 GMT]]></title><description><![CDATA[<p>Also zuerst mußt du wissen, WAS du da einlesen willst (das geht, indem du den ersten Teil der Zeile bis zum ersten Whitespace einliest und daraufhin entscheidest, was das nächste Objekt sein soll). Dann legst du per new ein Objekt des richtigen Typs an und rufst dessen Einlesemethode auf.</p>
<p>Diese Methode kann per strm.get() die Zwischenzeichen lesen und dazwischen per &gt;&gt; die einzelnen Elemente des Punktes einlesen:</p>
<pre><code class="language-cpp">void Point::read(istream&amp; strm)
{
  char ch;
  //wir starten am ( der Zeile
  strm.get(ch);if(ch!='(') return;
  int red,green,blue,style;
  strm&gt;&gt;red&gt;&gt;ch&gt;&gt;green&gt;&gt;ch&gt;&gt;blue;
  strm.get(ch);if(ch;!')') return;
  strm&gt;&gt;style&gt;&gt;skipws;
  ...

  setColor(Color(red,green,blue));
  this-&gt;style = (POINTSTYLE) style;
  ...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1072374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1072374</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 06 Jun 2006 11:08:09 GMT</pubDate></item><item><title><![CDATA[Reply to Object auslesen. on Wed, 07 Jun 2006 09:50:32 GMT]]></title><description><![CDATA[<p>Hat super Funktioniert.<br />
Hab paar Veränderrungen vorgenommen und stoße nun auf ein weiteres Problem.</p>
<p>Der Stream aus em geselen wird schaut so aus.<br />
<strong>POINT (123/231/122) 0 (2,111)</strong><br />
Die 0 Spielgelt den Style wieder.</p>
<pre><code>[cpp]void Point::read(istream&amp; strm)
{
  printf(&quot;Bin in POINT::read\n&quot;);
  int red,green,blue;
  char ch;
  red=blue=green=0;	
  while(strm.get(ch))
  {
	  if(ch=='(')
	  {
		  strm&gt;&gt;red&gt;&gt;ch&gt;&gt;green&gt;&gt;ch&gt;&gt;blue;
		  break;
	  }
  }
  strm.get(ch);if(ch!=')') return;
[b]strm&gt;&gt;style; // Hier liegt der Fehler[/b]
  strm&gt;&gt;xy;
  this-&gt;style=CROSS; // Workarround für Style
  Color c(red,green,blue);
  setColor(c);	 
}[/cpp]
</code></pre>
<p>Die Variable Style ist von Type POINTSTYLE</p>
<pre><code class="language-cpp">typedef enum 
{ 
      CROSS, CIRCLE, PIXEL  
} POINTSTYLE;
</code></pre>
<p>Fehlermeldung vom Compiler</p>
<blockquote>
<p>Point.cpp: In member function »virtual void Point::read(std::istream&amp;)«:<br />
Point.cpp:56: Fehler: no match für »operator&gt;&gt;« in »strm &gt;&gt; ((Point*)this)-&gt;Poin t::style«</p>
</blockquote>
<p>Irgendwie verstehe ich nicht warum der den operator bein nem enum anmekert.</p>
<p>Noch ne frage.<br />
Wie bekomme ich anstatt 0 den Wert CROSS in die Datei?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073026</guid><dc:creator><![CDATA[Z3D]]></dc:creator><pubDate>Wed, 07 Jun 2006 09:50:32 GMT</pubDate></item><item><title><![CDATA[Reply to Object auslesen. on Wed, 07 Jun 2006 09:55:14 GMT]]></title><description><![CDATA[<p>Es gibt keine Einles-Operationen für Enum's - d.h. du müsstest 'style' als int einlesen und dann in einen POINTSTYLE casten.</p>
<p>(die Alternative mit der Text-Darstellung benötigt eine Stringtabelle, mit der du zwischen dem Eingabetext (als String) und dem zugehörigen enum-Wert übersetzen kannst)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1073033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1073033</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 07 Jun 2006 09:55:14 GMT</pubDate></item></channel></rss>