RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 927 | Replies: 1 | Solved | Thread Tools  Display Modes
Reply
Join Date: Jul 2005
Location: Okc, OK
Posts: 25
Reputation: sifuedition is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sifuedition's Avatar
sifuedition sifuedition is offline Offline
Light Poster

File i/o question

  #1  
Sep 13th, 2005
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!!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Okc, OK
Posts: 25
Reputation: sifuedition is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sifuedition's Avatar
sifuedition sifuedition is offline Offline
Light Poster

Re: File i/o question

  #2  
Sep 13th, 2005
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).
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:51 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC