C++ examples for Data Type:bool
To turn debugging code on and off dynamically, create bool flags:
#include <iostream> #include <string> using namespace std; bool debug = false; int main(int argc, char* argv[]) { for(int i = 0; i < argc; i++) if(string(argv[i]) == "--debug=on") debug = true; bool go = true; while(go) {//from w ww . java 2 s. c o m if(debug) { cout << "Debugger is now on!" << endl; } else { cout << "Debugger is now off." << endl; } cout << "Turn debugger [on/off/quit]: "; string reply; cin >> reply; if(reply == "on") debug = true; // Turn it on if(reply == "off") debug = false; // Off if(reply == "quit") break; // Out of 'while' } }