Note that there are some explanatory texts on larger screens.

plurals
  1. POifstream fails without any reason?
    text
    copied!<p>I have a list of 3d spheres, when I save the list, I loop through:</p> <pre><code>void Facade::Save(std::ostream&amp; fs) { fs&lt;&lt;x&lt;&lt;" "&lt;&lt;y&lt;&lt;" "&lt;&lt;z&lt;&lt;" "&lt;&lt;r&lt;&lt;" "; //save fields fs&lt;&lt;color[0]&lt;&lt;" "&lt;&lt;color[1]&lt;&lt;" "&lt;&lt;color[2]&lt;&lt;std::endl; } </code></pre> <p>and when I restore the list, I use:</p> <pre><code> void Facade::Load(std::ifstream&amp; fs, BallList* blist) { GLfloat c[3]; fs&gt;&gt;x&gt;&gt;y&gt;&gt;z&gt;&gt;r; //fails there, why fs&gt;&gt;c[0]&gt;&gt;c[1]&gt;&gt;c[2]; ..... } </code></pre> <p>I don't know what goes wrong, but when reading the last line, the color components of the last sphere cannot be read, the stream fails after reading the radius of the last sphere. I checked the sphere list file:</p> <pre><code>7.05008 8.99167 -7.16849 2.31024 1 0 0 3.85784 -3.93902 -1.46886 0.640751 1 0 0 9.33226 3.66375 -6.93533 2.25451 1 0 0 6.43361 1.64098 -6.17298 0.855785 1 0 0 6.34388 -0.494705 -6.88894 1.50784 1 0 0 </code></pre> <p>This looks good. Can somebody tell me why is this happening? Is this a bug of ifstream? I'm using Unicode by the way.</p> <hr> <p>The loops are attached below:</p> <pre><code>void BallList::Load(std::istream&amp; fs) { Clear(); Facade ball1; while(!fs.fail() &amp;&amp; !fs.eof()) { ball1.Load(fs, this); Add(ball1); } /* balls.pop_back(); //this is a work around, get rid of the last one originalballs.pop_back(); */ } void BallList::Save(std::ostream&amp; fs) { vector&lt;Facade&gt;::iterator itero = this-&gt;originalballs.begin(); while (itero != this-&gt;originalballs.end()) { itero-&gt;Save(fs); itero++; } /* //work around the ifstream problem: the color of the last sphere cannot be read //add a dummy item as the last itero = this-&gt;originalballs.begin(); if(itero != this-&gt;originalballs.end()) { itero-&gt;Save(fs); } */ } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload