Elia Perantoni
Elia Perantoni

Reputation: 591

CLion is automatically printing back input from standard input, is there any fix for this?

I am trying out CLion to write some basic C++ programs but every time I feed in some input using std::cin or std::getline the input is printed back to the console for no reason.

For example if I run this program

#include <iostream>
#include <string>

int main(){
    string name;
    std::cin >> name;
    std::cout << name << std::endl;
    return 0;
}

and type thomas and press enter I get this output

thomas
thomas
thomas

when instead I should get just

thomas
thomas

I am using CLion/Mingw64 on Windows 10 x64

Upvotes: 7

Views: 2546

Answers (1)

Eldar Abusalimov
Eldar Abusalimov

Reputation: 25503

There's nothing wrong with your code.

What you observe is a side effect of using WinPTY under the hood. By default, CLion uses it to communicate with a debugged program on Windows.

Here's the corresponding bug in our issue tracker: CPP-2580 User input appears twice in output window in CLion under MinGW, please feel free to upvote the ticket.

While there's no proper fix for the issue yet, you may use a workaround suggested in comments to that ticket to disable PTY:

Open Registry via Find Action, type run.processes.with.pty and disable this pty setting.

Upvotes: 10

Related Questions