dynamicdebugflags.cpp

来自「Think in C++ 2nd」· C++ 代码 · 共 32 行

CPP
32
字号
//: C03:DynamicDebugFlags.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

#include <iostream>

#include <string>

using namespace std;

// Debug flags aren't necessarily global:

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) {

    if(debug) {

      // Debugging code here

      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'

  }

} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?