目录

运营商\u003e(operator >)

描述 (Description)

C ++函数std::vector::operator》测试第一个向量是否大于其他向量。

运算符>按顺序比较元素,比较在第一次不匹配时停止。

声明 (Declaration)

以下是std :: vector :: operator>函数形式std :: vector标头的声明。

template <class T, class Alloc>
bool operator>  (const vector<T,Alloc>& lhs, const vector<T,Alloc>& rhs);
  • v1 - 第一个向量。

  • v2 - 第二个向量。

返回值

如果第一个向量大于第二个,则返回true,否则返回false。

异常 (Exceptions)

这个函数永远不会抛出异常。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: vector :: operator>函数的用法。

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
   vector<int> v1 = {1, 2, 3, 4, 5};
   vector<int> v2;
   if (v1 > v2)
      cout << "v1 is greater than v2" << endl;
   v2.push_back(1);
   v2.push_back(2);
   v2.push_back(3);
   v2.push_back(4);
   v2.push_back(6);
   if (!(v1 > v2))
      cout << "v1 is not greater than v2" << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

v1 is greater than v2
v1 is not greater than v2
↑回到顶部↑
WIKI教程 @2018