Visual Studio C++ 字符串比较而不带声明
Visual studio C++ string compare without declaration
我想了解以下代码在Microsoft Visual Studio C/C++(2012版本)中的结果。实际上,当生成解决方案时,结果为"1"(True)。但是,单词"a"小于ASCII表中的单词"z"。因此,结果应为"0"(假)。即使我反转操作,平均值("z">"a")。结果为"1"。我也尝试了此操作("a"<"z")和("z"<"a"),结果是"0"任何人都可以解释我发生了什么?
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << ("a" > "z") << endl;
}
你的代码几乎和你写的一样:
const char s1[2] = {'a'};
const char s2[2] = {'z'};
int main()
{
cout << (s1 < s2) << endl;
}
因此,您可以看到您的代码实际上是在比较两个字符数组的地址。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么比较运算符如此快速
- 未在作用域中声明unordered_map
- 集合比较器的正向声明
- 如何在标头中声明比较函数
- 如何用类别的consumetrized构造函数声明使用类的比较对象设置的STL设置
- 未在范围内声明 - priority_queue C++的友元比较器类
- 声明具有免费功能的Unordered_set,以用于用户定义的哈希和比较
- 如何使用初始数据和自定义比较器声明 stl::p riority_queue
- 使用自定义比较器声明C++优先级队列的问题
- Visual Studio C++ 字符串比较而不带声明
- 比较条件中的字符串,而不将它们声明为字符串
- 比较两种声明数组的方法
- 如何在c++中声明带有指针类型比较器的set
- 嵌套循环内外变量声明的性能比较
- 如何声明比较操作符(小于)重载的模板特化
- 将比较操作符的重载定义/声明为库中的非成员函数
- 为什么 std::sort 不接受比较函数中声明的类
- 错误:声明与'function name'无法比较