我对C ++很陌生,对这个简单的代码有困难:
#include <iostream>
using namespace std;
int main() {
int NumberOfNonBlanks = 0;
int NumberOfUpperCase = 0;
char c;
while (cin >> c) {
++NumberOfNonBlanks;
if ((c>='A' && (c <= 'Z'))) {
++NumberOfUpperCase;
}
}
cout << "Nonblank characters : " << NumberOfNonBlanks << endl
<< "Uppercase characters : " << NumberOfUpperCase << endl;
}
我的操作系统是Windows,Ctrl + D似乎退出循环(Ctrl + Z没有做任何事情),但问题是它也会结束整个程序。因此,我在代码中的最后一行没有做任何事情......例如,如果我将输入输入为:
BLUE
然后按Ctrl + D,程序立即结束,返回值为0。
任何帮助将不胜感激为什么这种情况一直在发生。谢谢!
------------- EDIT -----------------
目前有一些争论认为ctrl + z并不表示对于CLion(在Windows上运行)的EOF。在这种情况下,有没有人知道CLion的任何解决方案?
答案 0 :(得分:0)
Ctrl + D
表示EOF,但它仅适用于Linux,如果您想在Windows或cmd中将EOF发送到您的程序,则需要使用Ctrl+Z
,您可以在此问题中查看更多内容Ctrl+D doesn't stop application from executing in command window
使用code :: block IDE
在我的窗口中Ctrl+Z
正常工作