switch case sting c++ code example
Example 1: c++ switch case statement
switch (n)
{
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
}
Example 2: c++ switch string
switch(str2int("my string"))
{
case str2int("my string")):
{
}
break;
}
constexpr unsigned int str2int(const char* str, int h = 0)
{
return !str[h] ? 5381 : (str2int(str, h+1) * 33) ^ str[h];
}