C++ 除錯技巧: Using Preprocessor Directive
Debug Tips -- using Preprocessor Directive #ifdef DEBUG /* Debug information */ #endif __LINE__ :被編譯的程式碼行號 __FILE__ :檔案名稱 __TIME__ :檔案被編譯的時間 __DATE__ :檔案被編譯的日期 g++ compile option: -DDEBUG // Sample Code #include <iostream> #include <vector> using std::vector; using std::cout; using std::string; using std::cin; using std::endl; int main() { cout << "File name: " << __FILE__ << endl; cout << "Compile at " << __DATE__ << ": " << __TIME__ << endl; #ifdef DEBUG cout << "Beginning execution of main().\n" ; #endif string word; vector< string > text; while ( cin >> word ) { #ifdef DEBUG cout << "word read: " << word << " at line: " << __LINE__ << "\n" ; #endif text.push_back( word ); } return 0; } 若您覺得文章寫得不錯,請點選文章上的...