使用断言

使用断言

程序一般分为 Debug 版本和 Release 版本,Debug 版本用于内部调试,Release 版本 发行给用户使用。

断言 assert 是仅在 Debug 版本起作用的宏,它用于检查“不应该”发生的情况。

一个内存复制函数。

在运行过程中,如果 assert 的参数为假,那么程序就会中 止(一般地还会出现提示对话,说明在什么地方引发了 assert)。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     
 7     //计算s=1+2+3...+100
 8     int s=0,n=1;
 9     while(n<=100) {
10         s=s+n;
11         n++;
12     }
13     cout<<"s="<<s<<endl;
14 
15     //累加键盘输入的数据
16     double x,sum=0.0;
17     cout<<"x=";
18     cin>>x;
19     while(x!=0) {
20         sum+=x;
21         cout<<"x=";
22         cin>>x;
23     }
24     cout<<"sum="<<sum<<endl;
25     return 0;
26 }
原文地址:https://www.cnblogs.com/borter/p/9406338.html