克里昂 - 回车?\ r

Hat*_*end 11 c special-characters carriage-return clion

我正在使用CLion IDE,我正在尝试回车.

我在C中做一个print语句,并具有以下语法:

printf("\rHello World!");这是一个循环.循环仍然Hello World在自己的行上打印.\n我的计划中没有.我已经尝试将line separators选项更改为unix mac OS,windows并且它们都没有更改功能.谷歌也让我没有得到有用的答案.

int main()
{
    int i = 0;
    while (i < 5000000)
    {
        printf("\rThis is line number %d!", i++);   
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的预期输出只是控制台窗口中的一行文本.

谢谢.

uta*_*uta 6

您的问题是PuTTY控制台,默认情况下在CLion中使用.您可以在注册表中将其关闭:

Help | Find Action | Registry... =>
run.processes.with.pty [ ] <- uncheck
Run Code Online (Sandbox Code Playgroud)

我建议你修改程序:

#include <iostream>

int main() {
    int i = 0;
    while (i < 500) {
        printf("\rThis is line number %d!", i++);
        fflush(stdout); // <- add this call
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)