0

I have g++ installed on Windows 10 with MinGW-w64, and when I run a program with an infinite loop and then I stop it with Ctrl+C, it only outputs the first std::cout after the loop. Here is an example:

#include <iostream>
using namespace std;

int main () {
    int n;
    while (cin>>n);
    cout<<n*2<<"."<<n*3<<"."<<n*4<<endl;
}

If I input 25 in the console and stop it with Ctrl+C, it outputs 50. But if I build the same program on my Ubuntu machine, input also 25 and exit the loop with Ctrl+D it outputs 50.75.100. Why is the behaviour different?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
Toomoch
  • 9
  • 1
  • `CTRL-C` and `CTRL-D` do totally different things. The Windows equivalent of your Linux systems `CTRL-D` is `CTRL-Z`. – πάντα ῥεῖ Jan 14 '21 at 19:59
  • Thanks! It waz CTRL-Z but you have to press ENTER after that, which is not needed in CTRL-C. Now it's working. – Toomoch Jan 14 '21 at 20:08
  • see https://stackoverflow.com/questions/29759979/ or https://stackoverflow.com/questions/43001734/ – M.M Jan 14 '21 at 20:26

0 Answers0