
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <multimap>
- C++ Library - <queue>
- C++ Library - <priority_queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- The C++ Advanced Library
- C++ Library - <any>
- C++ Library - <barrier>
- C++ Library - <bit>
- C++ Library - <chrono>
- C++ Library - <cinttypes>
- C++ Library - <clocale>
- C++ Library - <condition_variable>
- C++ Library - <coroutine>
- C++ Library - <cstdlib>
- C++ Library - <cstring>
- C++ Library - <cuchar>
- C++ Library - <charconv>
- C++ Library - <cfenv>
- C++ Library - <cmath>
- C++ Library - <ccomplex>
- C++ Library - <expected>
- C++ Library - <format>
- C++ Library - <future>
- C++ Library - <flat_set>
- C++ Library - <flat_map>
- C++ Library - <filesystem>
- C++ Library - <generator>
- C++ Library - <initializer_list>
- C++ Library - <latch>
- C++ Library - <memory_resource>
- C++ Library - <mutex>
- C++ Library - <mdspan>
- C++ Library - <optional>
- C++ Library - <print>
- C++ Library - <ratio>
- C++ Library - <scoped_allocator>
- C++ Library - <semaphore>
- C++ Library - <source_location>
- C++ Library - <span>
- C++ Library - <spanstream>
- C++ Library - <stacktrace>
- C++ Library - <stop_token>
- C++ Library - <syncstream>
- C++ Library - <system_error>
- C++ Library - <string_view>
- C++ Library - <stdatomic>
- C++ Library - <variant>
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ vector::operator>=() Function
The C++ vector::operator>=() function is used to test whether first vector is greater than or equal to other or not. It returns, true if the vector on the left side of the operator is greater than or equal to the vector that is on the right side or else it returns false. Operator >= compares element sequentially and comparison stops at first mismatch. This member function never throw an exception and the time complexity of the operator>=() function is linear.
Syntax
Following is the syntax for C++ vector::operator>=() Function −
bool operator>=(const vector<Type, Allocator>& left, const vector<Type, Allocator>& right);
Parameters
- left − It indicates the vector object type that is on the left side of the operator.
- right − It indicates the vector object type that is on the right side of the operator.
Example 1
Let's consider the following example, where we are going to use the opertor>=() function.
#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 or equal to v2" << endl; v1 = v2; if (v1 >= v2) cout << "v1 is greater than or equal to v2" << endl; return 0; }
Output
When we compile and run the above program, this will produce the following result −
v1 is greater than or equal to v2 v1 is greater than or equal to v2
Example 2
Considering the another scenario, where we are going to take char values and comparing them.
#include <iostream> #include <vector> int main(){ std::vector<char> myvector1{'H','E','L','L','O'}; std::vector<char> myvector2{'T','P'}; std::cout << std::boolalpha; std::cout << "myvector1 >= myvector2 is : " << (myvector1 >= myvector2) << '\n'; }
Output
On running the above program, it will produce the following result −
myvector1 >= myvector2 is : false
Example 3
In the following example, we are going to push_back() function to insert the values and applying operator>() function.
#include <vector> #include <iostream> int main( ){ using namespace std; vector <int> myvector1, myvector2; myvector1.push_back( 111 ); myvector1.push_back( 333 ); myvector1.push_back( 222 ); myvector2.push_back( 126 ); myvector2.push_back( 245 ); myvector2.push_back( 234 ); myvector2.push_back( 123 ); if ( myvector1 >= myvector2 ) cout << "myvector1 is greater than or equal to myvector2." << endl; else cout << "myvector1 is not greater than or equal myvector2." << endl; }
Output
When we execute the above program, it will produce the following result −
myvector1 is not greater than or equal myvector2.