|
|
@ -145,7 +145,7 @@ CString &CString::operator+=(const CString &source) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 按照字典顺序逐字对比 |
|
|
|
* 按照字典顺序对比 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool CString::operator>(const CString &compareString) const { |
|
|
|
bool CString::operator>(const CString &compareString) const { |
|
|
|
// 首先判断两CString对象data成员是否为空指针,空直接返回false
|
|
|
|
// 首先判断两CString对象data成员是否为空指针,空直接返回false
|
|
|
@ -158,14 +158,8 @@ bool CString::operator>(const CString &compareString) const { |
|
|
|
return length > compareString.length; |
|
|
|
return length > compareString.length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 以上情况都不符合时才进行逐字比较
|
|
|
|
// 以上情况都不符合时才进行比较
|
|
|
|
int compareLength = std::min(compareString.length, length); |
|
|
|
return strcoll(this->data, compareString.data) > 0; |
|
|
|
for (int i = 0; i < compareLength; ++i) { |
|
|
|
|
|
|
|
if (data[i] > compareString.data[i]) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &outputStream, const CString &source) { |
|
|
|
std::ostream &operator<<(std::ostream &outputStream, const CString &source) { |
|
|
@ -173,6 +167,8 @@ std::ostream &operator<<(std::ostream &outputStream, const CString &source) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::istream &operator>>(std::istream &inputStream, CString &source) { |
|
|
|
std::istream &operator>>(std::istream &inputStream, CString &source) { |
|
|
|
|
|
|
|
// 使用istream.get(char*, int)可以限制读入的长度,防止输入超长的字符串导致溢出,但是空格也会被读入
|
|
|
|
|
|
|
|
// 手动分割太麻烦,因此只好先用这种方法了
|
|
|
|
inputStream >> source.data; |
|
|
|
inputStream >> source.data; |
|
|
|
source.length = (int) strlen(source.data); |
|
|
|
source.length = (int) strlen(source.data); |
|
|
|
|
|
|
|
|
|
|
|