case

suggest change

Introduces a case label of a switch statement. The operand must be a converted constant expression of the promoted type of the condition. When the switch statement is executed, it jumps to the case label whose value equals the condition, if any.

char c = getchar();
bool confirmed;
switch (c) {
  case 'y':
    confirmed = true;
    break;
  case 'n':
    confirmed = false;
    break;
  default:
    std::cout << "invalid response!\n";
    abort();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents