How to fix the loop so it doesn't keep stopping with entries left in the file c++ -


I realize that I am posting my second post on this topic and thank you for all your patience It's going to work, since last post, it has been a few days since, and I'm still trying to understand why the loop is over after reading 15 out of the entries in the input file Emphasizing

My professor gives us a R, which contains the main () function and two files in the parameter, a sequential access input file and a random access output file, so in the abbreviation name-ad name header I have received all the other examples of working But I and my trainers are not able to understand what is happening and I can actually use some more help and some suggestions are very much Aha will.

  # include & lt; Iostream & gt; # Include & lt; Fstream & gt; # Include & lt; Iomanip & gt; using namespace std; Const int DESC_SIZE = 37; Structure item {int itemId; Description of the character [DESC_SIZE]; Double cost, value; }; Int ProcessIfile (Const four * Safffile, Const char * Raffey) {Fistruff Outfile, Infile; Item inventory; Int counter = 0; Int errorCode = 0; InFile.open (Saiffile, iOS :: In); OutFile.open (raffeil, ios :: out | iOS :: binary | iOS :: trunk); If (! InFile.fail ()) {cout & lt; & Lt; "Part ID Part Cost Part Value Part Details" & lt; & Lt; Endl; Cout & lt; & Lt; "==========================================" & lt; & Lt; Endl; InFile & gt; & Gt; Inventory.itemId; If (! InFile.eof ()) {while (! InFile.eof () & amp; Counter & lt; = 100 & amp; amp; amp; errorGood == 0) {inFile & gt; & Gt; Inventory.cast & gt; & Gt; Inventory.price; InFile.getline (Inventory Desscription, DESC_SECE); If (Inventory.Itmid! = Counter) Error code = -4; If (Inventory.Cast & lt; 0) errorCode = -5; If (Inventory.Price <0) errorCode = -6; Cout & lt; & Lt; "" & Lt; & Lt; Inventory. ITMID & lt; & Lt; "" & Lt; & Lt; Setup (5) & lt; & Lt; Inventory.cast & lt; & Lt; "" & Lt; & Lt; Setup (5) & lt; & Lt; Inventory.Presumes & lt; & Lt; "" & Lt; & Lt; Inventory Description & lt; & Lt; Endl; Counter ++; InFile & gt; & Gt; Inventory.itemId; } If (!InFile.eof ()) errorCode = -3; } And error code = -2; } And error code = -1; InFile.close (); Switch (error code) {case -1: cout & lt; & Lt; "Error: Input and / or output file can not be opened. \ N"; break; Case-2: Cot and LT; & Lt; "Error: empty input file. \ N"; break; Case-3: COAT & LT; & Lt; "Error: Over 100 records in the input file. \ N"; break; Case-4: COAT & LT; & Lt; "Error: Item ID number from order number in input id. \ N"; break; Case-5: COAT & LT; & Lt; "Error: Record found with negative cost in input file. \ N"; break; Case-6: COAT & LT; & Lt; "Error: Record found with negative value in input file. \ N"; break; } If (errorCode! = 0) return error code; Return counter;  

}

My best estimate is that this low The code is causing this problem:

  Infile & gt; & Gt; Inventory.cast & gt; & Gt; Inventory.price; InFile.getline (Inventory Desscription, DESC_SECE); If there is a new line after the input in   

input inventory.price , it will disrupt the following getline () statement, Since it stops when you reach a new line, you can ignore it by ignore :

  infile & gt; & Gt; Must be ignored with Inventory.cast & gt; & Gt; Inventory.price; InFile.ignore (); // & lt; == inFile.getline (Inventory Desassembly, DESC_SIZE);  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -