 <p>Because you work with statically allocated arrays you probably stumbled upon writing after the end of the array.</p> <p>You state that the file has exactly 21 entries but what happens with the eof condition? If you read the last entry, the stream still doesn't have the eof bit set. This only happens when you try to read and there is nothing. After the 21st entry, the loop still continues because the eof bit is not set. It reads garbage information and tries to store it into paInventory[21], but the array was only 21 in size.</p> <pre><code>//after last read x=21 and eof not set while (!InputInventory.eof () ) { //first read causes eof to be set InputInventory &gt;&gt; iTempPluCode &gt;&gt; sTempDescription &gt;&gt; dTempPrice &gt;&gt; iTempType &gt;&gt; dTempInventory; //Accessing paInventory[21] here which causes your error paInventory[x].setiPluCode(iTempPluCode); //...// } </code></pre>