What is happening here?

void palindromemgr(ifstream& in, ofstream& out, Stack& S)
{
    string c;  //candidate

  while (true)
  {
    cout << "entering first loop" << endl;   //debugging line
    if (in.eof()) break;
    in >> c;
    cout << "this is the value in c :" << c << endl;   //debugging line
    for (int a = 0;a < c.length();a++)
    {
      cout << "entering for loop" << endl;   //debugging line
      S.Push(c[a]);
    }
    while (true)
    {
      cout << "entering second loop" << endl;   //debugging line
      if (S.IsEmpty()) break;
      cout << S.Pop();
    }
    cout << endl;
  }
}

I expected this to read up to the first white space encountered in the input file, store that into the string c, grab each character in the string and push it into my stack (S), then output the contents of the stack, the loop through the rest of the input file the same way. Instead this is what I get.

entering first loop
this is the value in c :
entering second loop

entering first loop

AND it is deleting the contents of my input file!!!

If I comment out the line where I assign the value of the string and manually assign the value, this works. I.E

// in >> c;
c = "testing";

If the code above is used, the entire thing works (infinite loop of course, but the expected output). Obviously, the line in >> c; is not right but I have found SEVERAL examples done exactly this way (or so it seems).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.