Replaying the Tape to Restore State

The GetOperator() and GetOperand() functions in main.cpp can first get input from the saved tape. When that runs out, they can then get input from cin instead. Listing 16.2 shows how this works.

Listing 16.2. main.cpp Reading the Tape from a File
 1: #include <iostream> 2: #include <ios> 3: #include <fstream> 4: 5: #include "PromptModule.h" 6: #include "ErrorHandlingModule.h" 7: #include "AccumulatorModule.h" 8: #include "TapeModule.h" 9: #include "ExternalInterfaceModule.h" 10: 11: using namespace std; 12: *13: ifstream TapeInputStream; // Global variable for callback 14: 15: char GetOperator(void) 16: { 17: char Operator; 18: 19: if 20: ( *21: TapeInputStream.is_open() && *22: (!TapeInputStream.eof()) 23: ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.