假设我有以下代码:
我的问题是:系统如何检查它们之间的区别?
据我所知,不同的数据类型不能进行比较。我在这里错过了什么吗?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std; // or std::
int main()
{
string s1{ "Apple" };
cout << boolalpha;
cout << (s1 == "Apple") << endl; //true
}
我的问题是:系统如何检查它们之间的区别?
s1
是一个对象,而 "Apple"
是一个 C 风格字符串文本。据我所知,不同的数据类型不能进行比较。我在这里错过了什么吗?
basic_string
类的比较运算符。您可以在此页面中找到有关该类运算符的详细信息,包括operator==
、operator!=
、operator<
等。注意,数字7代表C++11标准所使用的版本,也可能会有其他版本可用。 - Jarod42std::string
。 - NathanOliver