关于stl的一个现象,大家讨论一下

Smile_Tiger Smile_Tiger 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:

#include "stdafx.h"
#include <string>
#include <vector>
#include <map>

int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> v;
int debug;

if(0 > (v.size()-100))
{
debug = 1;
}
else
{
debug = 2;
}
return 0;
}

其结果为debug = 2,为什么?

在vs2005和vc6.0下是这种结果,其他版本没有试验过,其中vs2005是安装了sp1补丁的

将代码改成如下这样

#include "stdafx.h"
#include <string>
#include <vector>
#include <map>

int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> v;
int debug;

int c = (v.size()-100);
if(0 > c)
{
debug = 1;
}
else
{
debug = 2;
}
return 0;
}

其结果为debug = 1
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
Smile_Tiger
C++ 语言 65,214 成员 250,514 内容