switch case c++ string code example
Example 1: c++ switch case statement
switch (n)
{
case 1:
break;
case 2:
break;
default:
}
Example 2: switch statement c++
switch(expression) {
case constant-expression :
statement(s);
break;
case constant-expression :
statement(s);
break;
default :
statement(s);
}
Example 3: how to make a switch case statement in c++
#include <iostream>
using namespace std;
int main(){
int num = 5;
switch(num + 2) {
case 1:
cout << "Case1: Value is: " << num << endl;
case 2:
cout << "Case2: Value is: " << num << endl;
case 3:
cout << "Case3: Value is: " << num << endl;
default:
cout << "Default: Value is: " << num << endl;
}
return 0;
}
Example 4: 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];
}
Example 5: switch case c++
switch (variable or an integer expression) {
case constant: {
break;
}
case constant: {
break;
}
default: {
break;
}
}
Example 6: switch in c++
switch (variable) {
case 1:
break
default:
break
}