lang == "Deutsch" || "deutsch"
is wrong
lang == "Deutsch" || lang == "deutsch"
is right
“deutsch” alone returns the address of the string in memory. which is
always not equal to zero. which means true.
a == "hello" || "bob"
means
(a == "hello") || "bob"
regardless of what a == "hello"
results in (true or false), false || "bob"
becomes false || pointer to "bob"
. All non-null pointers are true
, so this is false || true
which is true
.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout << "Language?" << endl;
string lang;
cin >> lang;
if(lang == "Deutsch" || lang == "deutsch")
{
cout << "Hallo Welt!";
}
else
{
return false;
}
if(lang == "English" || lang == "english")
{
cout << "Hello World!";
}
else
{
return false;
}
return 0;
}