我知道下面的代码正在输出布尔问题的结果,但我不明白为什么它输出 1 和 0 而不是 1 和 1。
#include <iostream>
using namespace std;
int main()
{
string d = "abc", e = "abc";
char a[] = "abc", b[] = "abc";
cout << (d == e);
cout << (a == b);
return 0;
}
//outputs 10
我还尝试输出存储在变量 a 和 b 中的值,并为两者获得相同的值
#include <iostream>
using namespace std;
int main()
{
string d = "abc", e = "abc";
char a[] = "abc", b[] = "abc";
cout << (d == e);
cout << (a == b);
cout << "\n" << a << "\n";
cout << b;
return 0;
}
// outputs 10
//abc
//abc