博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++语句switch语句_错误:案例标签不在C中的switch语句内
阅读量:2530 次
发布时间:2019-05-11

本文共 2145 字,大约阅读时间需要 7 分钟。

c++语句switch语句

The error: case label not within a switch statement occurs in C language with switch case statement, when switch (variable/value) statement is terminated by the semicolon (;).

错误:当switch(变量/值)语句由分号( ; )终止时,C语言中的case标签使用switch case语句以C语言出现。

Example:

例:

#include 
int main(void) {
int choice = 2; switch(choice); {
case 1: printf("Case 1\n"); break; case 2: printf("Case 2\n"); break; case 3: printf("Case 3\n"); break; case 4: printf("Case 4\n"); break; default: printf("Case default\n"); } return 0;}

Output

输出量

prog.c: In function ‘main’:prog.c:9:6: error: case label not within a switch statement      case 1:      ^~~~prog.c:11:10: error: break statement not within loop or switch          break;          ^~~~~prog.c:12:6: error: case label not within a switch statement      case 2:      ^~~~prog.c:14:10: error: break statement not within loop or switch          break;          ^~~~~prog.c:15:6: error: case label not within a switch statement      case 3:      ^~~~prog.c:17:10: error: break statement not within loop or switch          break;          ^~~~~prog.c:18:6: error: case label not within a switch statement      case 4:      ^~~~prog.c:20:10: error: break statement not within loop or switch          break;          ^~~~~prog.c:21:6: error: ‘default’ label not within a switch statement      default:      ^~~~~~~

How to fix?

怎么修?

See the statement switch(choice); it is terminated by semicolon (;) – it must not be terminated. To fix this error, remove semicolon after this statement.

参见语句switch(choice); 它以分号( ; )终止–一定不能终止。 要解决此错误,请在此语句后删除分号。

Correct code:

正确的代码:

#include 
int main(void) {
int choice = 2; switch(choice) {
case 1: printf("Case 1\n"); break; case 2: printf("Case 2\n"); break; case 3: printf("Case 3\n"); break; case 4: printf("Case 4\n"); break; default: printf("Case default\n"); } return 0;}

Output

输出量

Case 2

翻译自:

c++语句switch语句

转载地址:http://jbazd.baihongyu.com/

你可能感兴趣的文章
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
tomcat 7服务器跨域问题解决
查看>>
前台实现ajax 需注意的地方
查看>>
Jenkins安装配置
查看>>
个人工作总结05(第二阶段)
查看>>
Java clone() 浅拷贝 深拷贝
查看>>
深入理解Java虚拟机&运行时数据区
查看>>
02-环境搭建
查看>>
spring第二冲刺阶段第七天
查看>>
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>
BFS和DFS的java实现
查看>>
关于jquery中prev()和next()的用法
查看>>
一、 kettle开发、上线常见问题以及防错规范步骤
查看>>
eclipse没有server选项
查看>>
CRC码计算及校验原理的最通俗诠释
查看>>