0

I'm pretty new to C++ and having trouble with this simple code:

#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;
}

My operating system is Windows, and Ctrl+D seems to exit the loop (Ctrl+Z isn't doing anything), but the problem is that it ends the whole program as well. Thus, my last line in the code isn't doing anything... For example if I put in input as:

BLUE

then press Ctrl+D, the program finishes immediately with return value 0.

Any help would be appreciated why this keeps happening. Thanks!

-------------EDIT-----------------

There has been some arguments that ctrl + z does not indicate EOF for CLion (operating on windows) at the moment. Does anyone know any solutions for CLion in this case?

1 Answers1

0

Ctrl + D means EOF, but it only work in Linux, and if you want to send EOF to your program in windows or cmd, you need to use Ctrl+Z, you can see more from this question Ctrl+D doesn't stop application from executing in command window

And Ctrl+Z work fine in my windows with code::block IDE

  • Hmm but I'm using CLion instead of cmd, and pressing ctrl+z in the console makes no difference... Are you aware of why? –  Dec 05 '17 at 13:13
  • It seems that just a bug of Clion, here is some solution [sending EOF to stdin in Clion IDE](https://stackoverflow.com/questions/36405577/sending-eof-to-stdin-in-clion-ide), but I don't have a Clion so I didn't test it works or not – Huanfeng.Xu Dec 05 '17 at 13:27