accept
4829 / 3250 / 165
Регистрация: 10.12.2008
Сообщений: 10,569
|
07.09.2009, 03:37
|
|

Сообщение от Gravity
string вроде можно сравнивать как ==, хотя не помню точно.
там оно другое означает, то есть сама операция == по-другому работает (вроде из-за того, что перегружена)
отрывок с заголовка из include
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
| // operator ==
/**
* @brief Test equivalence of two strings.
* @param lhs First string.
* @param rhs Second string.
* @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
inline bool
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
{ return __lhs.compare(__rhs) == 0; } |
|
compare()
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| /**
* @brief Compare to a string.
* @param str String to compare against.
* @return Integer < 0, 0, or > 0.
*
* Returns an integer < 0 if this string is ordered before @a str, 0 if
* their values are equivalent, or > 0 if this string is ordered after
* @a str. Determines the effective length rlen of the strings to
* compare as the smallest of size() and str.size(). The function
* then compares the two strings by calling traits::compare(data(),
* str.data(),rlen). If the result of the comparison is nonzero returns
* it, otherwise the shorter one is ordered first.
*/
int
compare(const basic_string& __str) const
{
const size_type __size = this->size();
const size_type __osize = __str.size();
const size_type __len = std::min(__size, __osize);
int __r = traits_type::compare(_M_data(), __str.data(), __len);
if (!__r)
__r = __size - __osize;
return __r;
} |
|
0
|