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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.