C/C++之switch范围判断 发表于 2019-01-18 1 switch范围判断用法,使用’…’符12345678910111213141516171819202122#include <iostream>int main(int argc, char *argv[]){ int i = 5; switch (i) { case 0 ... 3: std::cout<<"0-3: "<<i<<std::endl; break; case 4 ... 6: std::cout<<"4-6: "<<i<<std::endl; break; case 7 ... 9: std::cout<<"7-9: "<<i<<std::endl; break; case 10: std::cout<<"10"<<i<<std::endl; default: break; } return 0;} 2 输出 4-6: 5