关于stl的一个现象,大家讨论一下
代码如下:
#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