C++中的std::string类实现了比较运算符。以下代码输出AAA
。
#include <iostream>
using namespace std;
int main() {
if("9">"111")
cout << "AAA";
else
cout << "not AAA";
return 0;
}
这段代码打印出
not AAA
:#include <iostream>
using namespace std;
int main() {
if("9">"111")
cout << "AAA";
else
cout << "not AAA";
if("99">"990")
cout << "BBB";
return 0;
}
为什么会这样?
std::string
?"blah"
不是一个std::string
。 - NathanOliverstd::string
和 C 字符串。 - user2486888const char*
值,而不是std::string
。 - user0042std :: string
,你需要在程序的某个地方声明、转换或以某种方式指定std :: string
。C++不会自动将字符串文字转换为std :: string
对象。 - PaulMcKenzie