To check if two vectors are equal in C++, you can use the `==` operator.
In this example,
vector1
and vector2
.==
operator to check if vector1
is equal to vector2
.==
operator returns true
if the vectors are equal, otherwise false
.#include <iostream>
#include <vector>
int main() {
std::vector<int> vector1 = {1, 2, 3};
std::vector<int> vector2 = {1, 2, 3};
bool are_equal = vector1 == vector2;
std::cout << std::boolalpha << are_equal;
return 0;
}
true
In this example,
vector1
and vector2
.==
operator to check if vector1
is equal to vector2
.==
operator returns true
if the vectors are equal, otherwise false
.#include <iostream>
#include <vector>
int main() {
std::vector<char> vector1 = {'a', 'b', 'c'};
std::vector<char> vector2 = {'a', 'b', 'c'};
bool are_equal = vector1 == vector2;
std::cout << std::boolalpha << are_equal;
return 0;
}
true
In this tutorial, we learned How to check if Two Vectors are Equal in C++ language with well detailed examples.