namespace std {
template <class CharT, class Traits, class Allocator>
bool operator==(const basic_string<CharT, Traits, Allocator>& a,
const basic_string<CharT, Traits, Allocator>& b); // (1) C++03
template <class CharT, class Traits, class Allocator>
bool operator==(const basic_string<CharT, Traits, Allocator>& a,
const basic_string<CharT, Traits, Allocator>& b) noexcept; // (1) C++14
template <class CharT, class Traits, class Allocator>
bool operator==(const CharT* a,
const basic_string<CharT, Traits, Allocator>& b); // (2)
template <class CharT, class Traits, class Allocator>
bool operator==(const basic_string<CharT, Traits, Allocator>& a,
const CharT* b); // (3)
}
概要
basic_string
オブジェクトの等値比較を行う。
デフォルトの比較では、大文字と小文字は区別される('a' == 'A'
はfalse
)。
なお、この比較方法はchar_traits
によってカスタマイズでき、大文字・小文字を区別しない比較もできる。
要件
- (3) パラメータ
b
が、Traits::length(b) + 1
の要素数を持つCharT
文字型の配列を指していること
戻り値
例
#include <iostream>
#include <string>
int main()
{
std::string a = "abc";
std::string b = "abc";
if (a == b) {
std::cout << "equal" << std::endl;
}
else {
std::cout << "not equal" << std::endl;
}
}
出力
equal