当前位置:   article > 正文

DEBUG C++ ——Debug_cpp 头文件debug

cpp 头文件debug

先看一段代码,大家可以先推测一下输出结果是什么?

//debugop.cpp

#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
 #ifdef DEBUG
   cout<<"Beginning execution of main() /n";
 #endif
 
 string word;
 vector<string> text;
 while(cin>>word)
 {
  #ifdef DEBUG
     cout<<"word read: "<<word<<"/n";
  #endif
     text.push_back(word);
 }
}

我在windows下使用微软的CL编译器。

d:/>cl debugop.cpp

d:/>debugop

运行结果没有Beginning execution of main()

而是直接等待用户输入word

也许很多人都希望看到Beginning execution of main() 的出现,这个时候需要用户了解预处理器指示符的应用

如果编译过程如下:

d:/>cl -DDEBUG debugop.cpp

d:/>debugop

运行结果就出现了Beginning execution of main()

然后等待用户输入word

这就是DEBUG预处理器指示符的应用。

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号