zl程序教程

您现在的位置是:首页 >  其他

当前栏目

C/C++ 难题困境 #15

2023-04-18 16:24:20 时间

问题:下面的代码能够输出正确的结果么?

#include <iostream>
#include <vector>
using namespace std;

int main()
{
   int myints[] = {100,100,100,100};
   vector<int> vCmp(myints, myints + sizeof(myints) / sizeof(int));
   vector<int> vCmp1(4,100);
   cout<<(vCmp == vCmp1)<<endl;
   cout<<(vCmp > vCmp1)<<endl;
   cout<<(vCmp < vCmp1)<<endl;
   cout<<(vCmp != vCmp1)<<endl;
    return 0;
}

本问题来源是因为在公司走查代码的时候发现一些同学在比较基础类型数据的vector时使用的是循环,然后逐一比对。因此写下上面的代码,欢迎大家讨论。