Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try</p> <pre><code>while(ifs.read((char *)&amp;two, sizeof(two))) </code></pre> <p>instead of</p> <pre><code>while(!(ifs.eof())) </code></pre> <p>Also try formatting your code :)</p> <pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; using namespace std; class Student { public: char FullName[40]; char CompleteAddress[120]; char Gender; double Age; bool LivesInASingleParentHome; }; int main() { /*Student one; strcpy(one.FullName, "Ernestine Waller"); strcpy(one.CompleteAddress, "824 Larson Drv, Silver Spring, MD 20910"); one.Gender = 'F'; one.Age = 16.50; one.LivesInASingleParentHome = true; ofstream ofs("fifthgrade.ros", ios::binary); ofs.write((char *)&amp;one, sizeof(one)); Student three; strcpy(three.FullName, "three Waller"); strcpy(three.CompleteAddress, "three 824 Larson Drv, Silver Spring, MD 20910"); three.Gender = 'M'; three.Age = 17; three.LivesInASingleParentHome = true; //ofstream ofs("fifthgrade.ros", ios::binary); ofs.write((char *)&amp;three, sizeof(three));*/ Student two; ifstream ifs("fifthgrade.ros", ios::binary); while(ifs.read((char *)&amp;two, sizeof(two))) { cout &lt;&lt; "Student Information\n"; cout &lt;&lt; "Student Name: " &lt;&lt; two.FullName &lt;&lt; endl; cout &lt;&lt; "Address: " &lt;&lt; two.CompleteAddress &lt;&lt; endl; if( two.Gender == 'f' || two.Gender == 'F' ) cout &lt;&lt; "Gender: Female" &lt;&lt; endl; else if( two.Gender == 'm' || two.Gender == 'M' ) cout &lt;&lt; "Gender: Male" &lt;&lt; endl; else cout &lt;&lt; "Gender: Unknown" &lt;&lt; endl; cout &lt;&lt; "Age: " &lt;&lt; two.Age &lt;&lt; endl; if( two.LivesInASingleParentHome == true ) cout &lt;&lt; "Lives in a single parent home" &lt;&lt; endl; else cout &lt;&lt; "Doesn't live in a single parent home" &lt;&lt; endl; cout &lt;&lt; "\n"; } return 0; } </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