帮我看看这个assert和NDEBUG

cumt_TTR 2011-03-16 11:17:18
#include <iostream>
#include <string>
#define NDEBUG //这里已经定义了NDEBUG了,为啥assert还起作用呢?
#include <cassert>
int main()
{
using namespace std;
string word;
cout<<"Enter a word:\n";
getline(cin,word);
const int iLength=6;
if(word.size()>iLength)
cerr<<"Error: "<<__FILE__
<<" : line "<<__LINE__<<endl
<<" Compiled on "<<__DATE__
<<" at "<<__TIME__<<endl
<<" Word read was "<<word
<<" Length too short"<<endl;
assert(word.size()==0); //当word.size!=0,assert还是起作用了,直接退出。
system("pause");
}
====================
还有就是当去除 #define NDEBUG的时候,assert起作用的时候屏幕一闪而过啊,看不到消息。。。。。。
用的DEV CPP
...全文
160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cumt_TTR 2011-03-18
  • 打赏
  • 举报
回复
#include <iostream>包含了<cassert>,谢谢楼上
zhangsongcui 2011-03-17
  • 打赏
  • 举报
回复
可能是#include <iostream>或#include <string>先包含了<cassert>
cumt_TTR 2011-03-17
  • 打赏
  • 举报
回复
来个人嘛
cumt_TTR 2011-03-16
  • 打赏
  • 举报
回复
还有人么
GoonYangXiaofang 2011-03-16
  • 打赏
  • 举报
回复
不一定是这个 NDEBUG 宏吧,用可能是 _NDEBUG ,或其他,看看 caasert 怎么定义 assert 的
雪人2015 2011-03-16
  • 打赏
  • 举报
回复

#include "stdafx.h"
#include <iostream>
#include <string>
#define NDEBUG //这里已经定义了NDEBUG了,为啥assert还起作用呢?
#include <cassert>
int main()
{
using namespace std;
string word;
cout<<"Enter a word:\n";
getline(cin,word);
const int iLength=6;
if(word.size()>iLength)
cerr<<"Error: "<<__FILE__
<<" : line "<<__LINE__<<endl
<<" Compiled on "<<__DATE__
<<" at "<<__TIME__<<endl
<<" Word read was "<<word
<<" Length too short"<<endl;
assert(word.size()==0); //当word.size!=0,assert还是起作用了,直接退出。
system("pause");
}



为什么我调试就没有问题呢?

vs2008

64,644

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧