Please support our C++ advertiser: Programming Forums
![]() |
What is happening here?
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!!!
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;
}
}
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).
// 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).
![]() |
Similar Threads
Other Threads in the C++ Forum
- Write to Screen and File{I-O question} (C++)
- Batch File Question (Windows NT / 2000 / XP / 2003)
- Another file I/O question (C++)
- Hosts file question about Gorilla's explanation (Viruses, Spyware and other Nasties)
- file sharing (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: problems with multimap...
- Next Thread: C++ or JAVA for beginnier
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode