小编Dmi*_*ist的帖子

对字符串使用小于比较运算符

我正在学习C++教程并查看字符串并使用+ =,==,!=等运算符进行重载,目前有一个简单的if语句

if(s1 < s2)
    cout << s2 <<endl;
else
  if(s2 < s1)
    cout << s1 << endl;
  else
    cout << "Equal\n";
Run Code Online (Sandbox Code Playgroud)

但这是如何工作的,程序如何决定哪个字符串比另一个字符串大?环顾四周我找到了一个基本的模板decleration:

template<class charT, class traits, class Allocator>
  bool operator< ( const basic_string<charT,traits,Allocator>& lhs,
                const basic_string<charT,traits,Allocator>& rhs );
Run Code Online (Sandbox Code Playgroud)

这会定义<工作方式吗?如果是这样,那意味着什么?

还做以下运算符对字符串有什么意义吗? - =和*=

任何意见是极大的赞赏!

c++ operator-overloading stdstring

13
推荐指数
1
解决办法
5万
查看次数

标签 统计

c++ ×1

operator-overloading ×1

stdstring ×1