I am having trouble getting my program to run correctly. Right now, when run as shown below, all I get is a never ending loop. Does anyone see issues that I may be able to fix?
# include <iostream> // Preprocessor Directive for cin and cout
# include <fstream> // Preprocessor Directive for File Input & Output
#include <cstdlib>
using namespace std;
Maybe you should change the (!infile.eof()) || (!infile.fail()) to infile.good() for simplicity? Just a suggestion... as what you have now is pretty much equivalent to !(infile.eof() && infile.fail()) which as you can see will only return false if both bits are true. :/
if it's not a scoping issue, you probably need to ignore a newline character or clear a bad bit; these are the most common causes of infinite loops when working with input streams for me
to read in individual characters. the stream extraction operator tries to write everything to the variable until the next whitespace character, so there's a bunch of crap sitting in the input stream buffer, so you immediately have a bad bit, just not a fail bit.
use this:
yourVariable = infile.get();
that will read in only one character at a time which is what i believe you are trying to do
Sorry about the lack of code tags. This is my first time posting on the boards.
Thanks so much for identifying the likely problem. I will try that out first thing in the morning. Forgive me for the stupidity, but how do I change the scope?
what i mean about your scope is that you need an opening curly brace immediately after your while loop test condition. if you don't have that, the only thing that's going to run in the loop is the very first statement after your loop condition. everything after that line won't execute until the loop finishes. and all you've done in the loop is overwrite those variables a whole bunch of times