搜尋此網誌

2025年7月20日星期日

Switch statements

In C++, a switch statement is used to execute one out of multiple code blocks based on the value of a variable. It’s especially handy when dealing with multiple if-else conditions that all check the same variable.

handy: easy to use or to do

The expression must evaluate to an integral or enumeration type (int, char, enum, etc.).

Each case compares the expression against a constant.

Use break to stop execution after a matching case—if omitted, execution "falls through" to the next case.

Default is optional and acts as a fallback when no case matches.

std::flush is a stream manipulator in C++ used to force the output buffer to flush immediately—meaning all characters that have been sent to the stream are written out, even if the buffer isn’t full

Microsoft Copilot

沒有留言:

發佈留言