0

I want to read from a file.txt that looks like this:

process_id run_time arrival_time

T1 23 0

T2 75 5

then I will save in arrays

My problem is: the 1st iteration outputs: T 1 2 and that's incorrect

any help please? thanks

while (!ManageFile.eof()) 
{


    ManageFile>>rubbish; //read the word process_id
    ManageFile>>rubbish; //read the word run_time
    ManageFile>>rubbish; //read the word arrival_time

    while (true) 
    {
    ManageFile>>process_id[i];
    cout << process_id[i]<<endl;
    ManageFile>>run_time[i];
    cout << run_time[i]<<endl;
    ManageFile>>arrival_time[i];
    cout << arrival_time[i]<<endl;
    i++;
    }
CodeX
  • 17
  • 1
  • 7
  • Please, Please, search StackOverflow for "c++ read file array" before continuing. There are too many similar questions to yours, but since they are not *exactly* duplicate, I can't close this as duplicate. – Thomas Matthews Nov 19 '14 at 21:14
  • http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong – Neil Kirk Nov 19 '14 at 21:16
  • Why do you have an infinite loop that never exits? – Neil Kirk Nov 19 '14 at 21:17
  • it loops till the end of the lines of the file – CodeX Nov 19 '14 at 21:18
  • 1
    @MaramAlaa Not true. Inner while is going to loop infinitely. Btw. what is type of `process_id` ? You are almost sure read only one `byte/char/...` – skywall Nov 19 '14 at 21:30
  • @MaramAlaa `while(true)` loops until a flow control statement pulls execution out of its scope (like `break`) or the program otherwise terminates. With that in mind, `eof` should rarely be a loop control for input anyway, you probably want to use `while (ManageFile>>process_id[i])` as your second loop and take out the first. – IllusiveBrian Nov 19 '14 at 21:30

0 Answers0