CLion 会自动从标准输入打印回输入,是否有任何解决方法?

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

我正在尝试使用 CLion 编写一些基本的 C++ 程序,但每次我使用 std::cinstd::getline 输入一些输入时,输入都会无缘无故地打印回控制台。

例如如果我运行这个程序

#include <iostream>
#include <string>

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

然后输入 thomas 并按回车键我得到这个输出

thomas
thomas
thomas

什么时候我应该得到

thomas
thomas

我在 Windows 10 x64

上使用 CLion/Mingw64

你的代码没有问题。

您观察到的是在后台使用 WinPTY 的副作用。默认情况下,CLion 使用它与 Windows.

上的调试程序通信

这是我们的问题跟踪器中的相应错误:CPP-2580 User input appears twice in output window in CLion under MinGW,请随时为票证投票。

虽然目前还没有针对该问题的适当修复,但您可以使用该票证评论中建议的解决方法来禁用 PTY:

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