C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Operator> =

C++ Operator>=

C++ multiset Operator> = 是C++中 multiset 的非成员重载函数 。此功能用于检查第一个 multiset 是否大于或等于另一个。
注意: Operator>=顺序比较multiset的元素,比较将在第一次不匹配时停止。

语法

template <class T, class Compare, class Allocator>
  bool operator>= ( const multiset<T,Compare,Allocator>& lhs,
                    const multiset<T,Compare,Allocator>& rhs );

参数

lhs : 第一个 multiset 对象。
rhs : 第二个 multiset 对象。

返回值

它返回 true >如果 multiset 容器对象的左侧大于或等于 multiset 容器对象的右侧,否则为 false 。

复杂度

如果lhs和rhs的大小不同,则复杂度将保持不变。
否则,lhs和rhs的大小将达到线性。

迭代器的有效性

没有更改。

数据竞争

访问容器,lhs和rhs。
同时

异常安全性

该函数不会引发异常。

示例1

让我们看一个简单的示例,检查第一个 multiset 是否大于或等于:
#include <iostream>
#include <set>
using namespace std;
int main() {
   multiset<char> m1;
   multiset<char> m2;
   m1.emplace('a');
   m2.emplace('a');
   if (m1 >= m2)
      cout << "Multiset m1 is greater than or equal to m2." << endl;
   m2.emplace('b');
   if (!(m1 >= m2))
      cout << "Multiset m1 is not greater than or equal to m2." << endl;
   return 0;
}
输出:
Multiset m1 is greater than or equal to m2.
Multiset m1 is not greater than or equal to m2.
在上面的示例中,有两个 multiset m1和m2、 m1和m2包含一个元素。当我们比较两个 multiset 时,它将显示消息" multiset m1大于或等于m2",并且在向m2添加一个元素之后,它将显示消息" multiset m1不大于或等于m2"。

示例2

让我们看一个简单的示例:
#include <set>  
#include <iostream>  
  
using namespace std; 
   
int main( )  
{   
   multiset < int > m1, m2, m3, m4;  
   int i;  
  
   for ( i = 1 ; i < 3 ; i++ )  
   {  
      m1.insert ( i );  
      m2.insert (i * i );  
      m3.insert ( i-1 );  
      m4.insert ( i );  
   }  
  
   if ( m1 >= m2 )  
      cout << "Multiset m1 is greater than or equal to multiset m2." << endl;  
   else  
      cout << "The multiset m1 is less than the multiset m2." << endl;  
  
   if ( m1 >= m3 )  
      cout << "Multiset m1 is greater than or equal to multiset m3." << endl;  
   else  
      cout << "The multiset m1 is less than the multiset m3." << endl;  
  
   if ( m1 >= m4 )  
      cout << "Multiset m1 is greater than or equal to multiset m4." << endl;  
   else  
      cout << "The multiset m1 is less than the multiset m4." << endl;  
      
      return 0;
}
输出:
The multiset m1 is less than the multiset m2.
Multiset m1 is greater than or equal to multiset m3.
Multiset m1 is greater than or equal to multiset m4.

示例3

让我们看一个简单的示例:
#include <iostream>
#include <set>
 
using namespace std;
int  main () 
{ 
  multiset < int >  s1 ,  s2 ; 
  s1 . insert ( 10 ); 
  s1 . insert ( 20 ); 
  s1 . insert ( 30 ); 
  s2  =  s1 ;
  cout  <<  ( s1  >=  s2 )  << endl ;
  s2 . insert ( 40 );
  cout  <<  ( s1  >=  s2 )  <<  endl ; 
  
  return 0;
}
输出:
1
0
在上面的示例中,如果m1大于或等于m2,则它将返回1,否则将返回0。

示例4

#include <set>  
#include <iostream>  
using namespace std; 
  
int main ()  
{  
   multiset<string> m2;
   typedef multiset<string> login; 
   
   m2 = {"xyz@123"} ; //stored id and password
   
   string password;
   login m1;
   
       cout<<"---------Login----------"<<endl<<endl;
       cout<<"Enter password: \n";
       cin>> password;       // Get value
       m1.insert(password);   // Put them in multiset
     cout<<"Password you have entered: \n";
     for (auto it = m1.begin(); it != m1.end(); it++) {
        cout << (*it)<< endl;
      }
      cout<<"Password stored in the system :\n";
     for (auto it = m2.begin(); it != m2.end(); it++) {
        cout << (*it)<< endl;
     }
  
   if (m1 >= m2)  
        cout << "\nWelcome to your Page..." << endl;
   else  
        cout << "\nIncorrect Password..." << endl;
      return 0;
}
输出:
1).
---------Login----------
Enter password: 
xyz@123
Password you have entered: 
xyz@123
Password stored in the system :
xyz@123
Welcome to your Page...
2).
---------Login----------
Enter password: 
abc@122
Password you have entered: 
abc@122
Password stored in the system :
xyz@123
Incorrect Password...
在上面的示例中,有两个 multiset m1和m2、 m1包含存储的密码,第二个 multiset m2存储用户输入的密码。它检查m1是否大于或等于m2、如果密码m1大于或等于m2,则登录成功,否则登录失败。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4