赞
踩
先看一段代码,大家可以先推测一下输出结果是什么?
//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预处理器指示符的应用。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。