O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required