Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 807
Elia Perantoni Avatar asked Jan 03 '23 08:01

Elia Perantoni


1 Answers

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.

like image 136
Eldar Abusalimov Avatar answered Jan 25 '23 23:01

Eldar Abusalimov