infile >> instruction;
reads a word from a file (a sequence of non-whitespace characters) and stores it in "instruction". In your case, it reads "A" and stores that.getline(infile, instruction);
reads what's left of the line and stores it in "instruction". In your case, it reads " BC DEF".while(!infile.eof())
is an error: this loop always reads past end of file. Correct input loop has the structure
|
|
|
|