Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::fstream File prints junk at end of reading
    primarykey
    data
    text
    <p>Im writing a program to practice with the language, but im getting some pretty weird output from code that seems right to me.</p> <p>The code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;list&gt; struct Car { std::string make; std::string model; int partNo; double price; int quantity; std::string partname; }; void AddItem(); void _Update(int PartNo, int quantity); void UpdateList(std::list&lt;Car&gt;&amp; _Car); int main() { std::list&lt;Car&gt; _Car; UpdateList(_Car); for(std::list&lt;Car&gt;::iterator iter = _Car.begin(); iter != _Car.end(); iter++) { std::cout &lt;&lt; iter-&gt;make &lt;&lt; " " &lt;&lt; iter-&gt;model &lt;&lt; " " &lt;&lt; iter-&gt;partNo &lt;&lt; " " &lt;&lt; iter-&gt;price &lt;&lt; " " &lt;&lt; iter-&gt;quantity &lt;&lt; " " &lt;&lt; iter-&gt;partname &lt;&lt; std::endl; } } void UpdateList(std::list&lt;Car&gt;&amp; _Car) { std::ifstream File("CarParts.txt"); if(!File.is_open()) std::cerr &lt;&lt; "Bad file input....... closing...."; while(!File.eof()) { Car tempObj; File &gt;&gt; tempObj.make &gt;&gt; tempObj.model &gt;&gt; tempObj.partNo &gt;&gt; tempObj.price &gt;&gt; tempObj.quantity; getline(File,tempObj.partname); _Car.push_back(tempObj); } File.close(); } </code></pre> <p>Outpost given:</p> <pre><code> Pajero NA1H25 1 3.65 11 BLADE W/S WIPER Honda_Sivic R34gFk 2 4.97 15 ENGINE CHANGE 2 4.97 15 </code></pre> <p>Notepad file:</p> <pre><code>Pajero NA1H25 1 3.65 11 BLADE W/S WIPER HondaSivic R34gFk 2 4.97 15 ENGINE CHANGE </code></pre> <p>what is with the three numbers under the two lines i actually wanted printed out? It's really confusing me... Thanks if you can help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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