1.0 KiB
1.0 KiB
operator== / operator!=
inline bool operator==(const String& lhs, const String& rhs);
inline bool operator!=(const String& lhs, const String& rhs);
判断两个字符串是否相等或不相等。
operator==: 比较两个字符串的长度是否相等,以及内容是否相同。
operator!=: 相当于 !(lhs == rhs)。
参数:
lhs- 左侧字符串rhs- 右侧字符串
返回: 布尔值,表示比较结果
复杂度: O(n),其中 n 为字符串长度
示例:
#include "XCEngine/Core/Containers/String.h"
#include <iostream>
int main() {
XCEngine::Containers::String s1("Hello");
XCEngine::Containers::String s2("Hello");
XCEngine::Containers::String s3("World");
std::cout << std::boolalpha;
std::cout << (s1 == s2) << std::endl; // 输出: true
std::cout << (s1 == s3) << std::endl; // 输出: false
std::cout << (s1 != s3) << std::endl; // 输出: true
return 0;
}
相关文档
- String 总览 - 返回类总览