use*_*218 2 c++ switch-statement
#include <iostream>
#include <sstream>
int main(int argc, char* argv[]) {
if ( argc != 2 ) {
std::cout << "usage: " << argv[0] << " <n> " << std::endl;
return 0;
}
std::stringstream strm;
strm << argv[1];
int count = 0;
int number;
strm >> number;
switch ( number ) {
case 0: ++count;
case 1: ++count;
case 2: ++count;
case 3: ++count;
case 4: ++count;
}
std::cout << "count: " << count << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个新手问题,但我刚开始使用C++.我参加了一个游戏设计课程,这是教授在SVN上的第一个例子.当我在编译后运行编程时,
./run 4(即我给出参数4)我得到一个输出:count:1
./run 3我得到一个输出:count:2
./run 1计数:4
./run 0计数:5
由于count初始化为0,为什么会出现./run 1给出4或./run 0给出计数5.
我真的很抱歉这个愚蠢的问题,但我要感谢任何解释.
在此先感谢您的问候
| 归档时间: |
|
| 查看次数: |
3477 次 |
| 最近记录: |