⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctdebug.cpp

📁 C++高级编程这本书所附的源代码
💻 CPP
字号:
// CTDebug.cpp#include <exception>#include <fstream>#include <iostream>using namespace std;#ifdef DEBUG_MODEofstream debugOstr;const char* debugFileName = "debugfile.out";#endifclass ComplicatedClass{public:  ComplicatedClass() {}  // class details omitted for brevity};class UserCommand{public:  UserCommand() {}  // class details not shown for brevity};ostream& operator<<(ostream& ostr, const ComplicatedClass& src);ostream& operator<<(ostream& ostr, const UserCommand& src);UserCommand getNextCommand(ComplicatedClass* obj);void processUserCommand(UserCommand& cmd);void trickyFunction(ComplicatedClass* obj) throw(exception);int main(int argc, char** argv){#ifdef DEBUG_MODE  // open the output stream  debugOstr.open(debugFileName);  if (debugOstr.fail()) {    cout << "Unable to open debug file!\n";    return (1);  }  // Print the command-line arguments to the trace  for (int i = 0; i < argc; i++) {    debugOstr << argv[i] << " ";    debugOstr << endl;  }#endif  ComplicatedClass obj;  trickyFunction(&obj);  // Rest of the function not shown  return (0);}ostream& operator<<(ostream& ostr, const ComplicatedClass& src){  ostr << "ComplicatedClass";  return (ostr);}ostream& operator<<(ostream& ostr, const UserCommand& src){  ostr << "UserCommand";  return (ostr);}UserCommand getNextCommand(ComplicatedClass* obj){  UserCommand cmd;  return (cmd);}void processUserCommand(UserCommand& cmd){  // details omitted for brevity}void trickyFunction(ComplicatedClass* obj) throw(exception){#ifdef DEBUG_MODE  // If in debug mode, print the values with which this function starts  debugOstr << "trickyFunction(): given argument: " << *obj << endl;#endif  while (true) {    UserCommand cmd = getNextCommand(obj);#ifdef DEBUG_MODE    debugOstr << "trickyFunction(): retrieved cmd " << cmd << endl;#endif    try {      processUserCommand(cmd);    } catch (exception& e) {#ifdef DEBUG_MODE      debugOstr << "trickyFunction(): "                << " received exception from procesUserCommand(): "                << e.what() << endl;#endif      throw;    }  }}

⌨️ 快捷键说明

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