C++17在if语句内或switch语句内完成变量的定义及初始化:
#includeusing namespace std; int get() { return 5; } int main() { if(int a=get(); a != 8) { cout<<"a="<
通过这种方式定义变量及其初始化,可以将变量的有效作用域限制在if或switch语句的范围内,减少外围作用域内变量的名称混淆。

C++17在if语句内或switch语句内完成变量的定义及初始化:
#includeusing namespace std; int get() { return 5; } int main() { if(int a=get(); a != 8) { cout<<"a="<
通过这种方式定义变量及其初始化,可以将变量的有效作用域限制在if或switch语句的范围内,减少外围作用域内变量的名称混淆。