Clion scanf 复制上一行

标签 c mingw clion

我是 C 的新手,我正在学习一些教程,但在 CLion 中运行代码时我总是遇到错误。

每当我使用 scanf 时,它似乎总是重复控制台中的前一行。

这是它输出的内容:

Please enter your first number:5
Please enter your first number: 5
Please enter your second number:6
Please enter your second number: 6
5 < 6
Process finished with exit code 0

这是我认为它应该输出的内容:

Please enter your first number:5
Please enter your second number:6
5 < 6
Process finished with exit code 0

当然,这是我的代码:

#include <stdio.h>

int main()
{
    int no1;
    int no2;

    printf("Please enter your first number: ");
    scanf(" %d", &no1);

    printf("Please enter your second number: ");
    scanf(" %d", &no2);

    if(no1 < no2){
        printf("%d < %d", no1, no2);
    } else if (no1 == no2) {
        printf("Both numbers are %d", no1);
    } else {
        printf("%d > %d", no1, no2);
    }

    return 0;
}

我也在使用 MinGW 3.21、CMake 3.5.1

编辑: 我只是在普通命令行上运行代码,发现这不是问题。它似乎只是 CLion 的控制台。

最佳答案

这是 CLion 控制台中的错误 - CPP-2580 有两种可能的解决方法:

  1. 关闭 PTY:通过禁用注册表中的 run.processes.with.pty 选项(帮助 -> 查找操作 -> 注册表...)
  2. 使用 Cygwin 而不是 MinGW

关于Clion scanf 复制上一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514177/

相关文章:

将 float 转换为字节数组的 C 函数

C Eclipse 语义错误?

c++ - VC++允许/##/作为宏的值——如何在eclipse/mingw-gcc中处理它?

mingw - Qt5.6中的跨平台Webview

c++ - 如何使用 cmake 链接到 awesomium

Clion 排序包含语句

C数组在一定范围内反转

c - OpenCL:对内置函数的调用不明确

qt - 让 Qt Creator 使用 MinGW

c++ - 无法运行任何c/c++程序