The condition in the if statement
if(lang == "Deutsch" || "deutsch")
is equivalent to the following condition
if( ( lang == "Deutsch" ) ||( "deutsch" ) )
Independing on whether the left subexpression of the operatir || will yield true of false the right subexpression is always yields true
because string literals used in expressions are converted to pointers to their first characters. And because the address of a string literal is not equal to 0 then the subexpression is converted to boolean value true.
It is obvious that you mean the following condition
if(lang == "Deutsch" || lang == "deutsch")
According to the C++ Standard (4.12 Boolean conversions)
1 A prvalue of arithmetic, unscoped enumeration, pointer, or
pointer to member type can be converted to a prvalue of type bool. A
zero value, null pointer value, or null member pointer value is
converted to false; any other value is converted to true.
And (5 Expressions)
9 Whenever a glvalue expression appears as an operand of an operator
that expects a prvalue for that operand, the lvalue-to-rvalue (4.1),
array-to- pointer (4.2), or function-to-pointer (4.3) standard
conversions are applied to convert the expression to a prvalue.
Take into account that string literals in C++ have types of constant character arrays as it is said in the quote they are converted to pointers in expressions.
Also you need to include header <string>
and should exclude header "windows.h"
because neither declaration from the header is used in the program.
Your program then it could be written the following way
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Language?" << endl;
string lang;
cin >> lang;
if ( lang == "Deutsch" || lang == "deutsch" )
{
cout << "Hallo Welt!" << endl;
}
else if ( lang == "English" || lang == "english" )
{
cout << "Hello World!" << endl;
}
return 0;
}