簡體   English   中英

克里昂 - 回車? \ r

[英]CLion - Carriage return? \r

我正在使用CLion IDE,我正在嘗試回車。

我在C中做一個print語句,並具有以下語法:

printf("\\rHello World!"); 這是一個循環。 循環仍然在自己的行上打印每個Hello World 我的程序中沒有\\n 我已經嘗試將line separators選項更改為unix mac OSwindows ,但沒有一個更改功能。 谷歌也讓我沒有得到有用的答案。

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

    return 0;
}

我的預期輸出只是控制台窗口中的一行文本。

謝謝。

您的問題是PuTTY控制台,默認情況下在CLion中使用。 您可以在注冊表中將其關閉:

Help | Find Action | Registry... =>
run.processes.with.pty [ ] <- uncheck

我建議你修改程序:

#include <iostream>

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

    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM