程序无法正常运行 [英] program won't run properly
本文介绍了程序无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码摘自Lippman的最新版C ++ Primer
The following code is from the recent edition of C++ Primer by Lippman
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char ch;
// initialize counters for each vowel
int aCnt = 0, eCnt = 0, iCnt = 0,
oCnt = 0, uCnt = 0;
while (cin>>ch ) {
// if ch is a vowel, increment the appropriate counter
switch (ch) {
case ''a'':
++aCnt;
break;
case ''e'':
++eCnt;
break;
case ''i'':
++iCnt;
break;
case ''o'':
++oCnt;
break;
case ''u'':
++uCnt;
break;
}
}
// print results
cout << "Number of vowel a: \t" << aCnt << ''\n''
<< "Number of vowel e: \t" << eCnt << ''\n''
<< "Number of vowel i: \t" << iCnt << ''\n''
<< "Number of vowel o: \t" << oCnt << ''\n''
<< "Number of vowel u: \t" << uCnt << endl;
system("pause");
return 0;</iostream>
它显示了极差的结果.我不能让它读取文件.其他时间
跑步时,我输入字符并按^ z,然后在长时间停顿后显示.
如何使其正常工作.
It shows its results extremly poorly. I can''t make it read files. Other times
upon running, I type in characters and hit ^z then it shows after a long pause.
How can I make it work properly.
推荐答案
while
循环没有退出条件.
我如何使其正常工作?" —好吧,这取决于您适当"的意思.如果需要,请在while
行后添加退出条件,例如
Thewhile
loop has no exit condition.
"How can I make it work properly?" — well, it depends what do you mean "properly". If you want, add a condition for exit right after line withwhile
, such as
while (cin>>ch ) {
if (ch == 'q') break;
switch (ch) {
//...
}
}
在这种情况下,循环将在"q"(退出")上退出.
in this case the loop will exit on ''q'' ("quit").
这篇关于程序无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文