64,644
社区成员
发帖
与我相关
我的任务
分享
#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");
}