Ignore Function

My teacher told me "The ignore function can be used to skip over (ignore) input. Read the discussion on page 133 of the textbook to find out how to ignore the rest of a line of input."

Unfortunately I don't own the book so was hoping I could get some help.
I tried:
input.ignore(80,'\n'); //line will not exceed 80 characters
but that didn't seem to work.
What do you mean by it didn't seem to work?
Maybe you're looking for std::cin.ignore();?
My function looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void get_Changes(Workers_rec Worker[], int& n)
{
  ifstream input;
  string ChangesFile;
  int TempID, NotHere=0;
  char ComCode, NewStatus;
  double NewRate;
  cout << "Enter the name of change file" << endl;
  cin >> ChangesFile;
  input.open(ChangesFile.c_str());
  input >> TempID;
  while (!input.eof())
    {
      for (int i=0; i<n; i++)
        if (Worker[i].IDNum == TempID)
          {
            input >> ComCode;
            if (ComCode == 's' || ComCode == 'S')
              {
                input >> NewStatus;
                Worker[i].Status = NewStatus;
                cout << "ID# " << Worker[i].IDNum << " status changed to " << Worker[i].Status << endl;
              }
            if (ComCode == 'p' || ComCode == 'P')
              {
                input >> NewRate;
                Worker[i].Rate = NewRate;
                cout << "ID# " << Worker[i].IDNum << " pay rate changed to " << Worker[i].Rate << endl;
              }
            NotHere++;
            if (NotHere == n+1){
              input.ignore(80,'\n');
              cout << "ID# " << TempID << " is not valid" << endl;
            }
          }
      NotHere = 0;
      input >> TempID;
    }
  cout << endl;
}


it inputs:
555 p 18.25
56 s F
11 nonsense to be ignored
555 S p

but it only outputs:
ID# 555 pay rate changed to 18.25
ID# 56 status changed to F

until it gets stuck waiting for input. I assumed it was an error with the ignore function but it might be the method I tried to activate it.
Last edited on
Figured it out
Last edited on
Topic archived. No new replies allowed.