问题描述
我正在使用CLion IDE,并且试图执行回车。
我正在用C语言执行一条print语句,语法如下:
printf( \rHello World!);
处于循环内。循环仍然在其自己的行上打印每个 Hello World
。我的程序中没有 \n
。我尝试将换行符
选项更改为 unix
mac OS
和 windows
,它们都没有更改功能。 Google也使我找不到有用的答案。
int main()
{
int i = 0;
while(i {
printf( \r这是行号%d!,i ++);
}
返回0;
}
我的预期输出只是控制台窗口中的单行文本。 / p>
谢谢。
您的问题是使用的PuTTY控制台默认情况下在CLion中。
您可以在注册表中将其关闭:
帮助|查找动作|注册表... =>
run.processes.with.pty []<-取消选中
我建议您修改程序:
#include< iostream>
int main(){
int i = 0;
while(i< 500){
printf( \r这是行号%d!,i ++);
fflush(stdout); //<-添加此调用
}
返回0;
}
I am using the CLion IDE and I am trying to do a carriage return.
I am doing a print statement in C and have the following syntax:
printf("\rHello World!");
which is inside a loop. The loop still prints every Hello World
on its own line. There are no \n
's in my program. I've tried changing the line separators
options to unix
mac OS
and windows
and none of them change the functionality. Google has also led me to no useful answers.
int main()
{
int i = 0;
while (i < 5000000)
{
printf("\rThis is line number %d!", i++);
}
return 0;
}
My expected output is only a single line of text in the console window.
Thanks.
Your problem is PuTTY console, that is used in CLion by default.You can switch it off in Registry:
Help | Find Action | Registry... =>
run.processes.with.pty [ ] <- uncheck
I recommend you modify the program:
#include <iostream>
int main() {
int i = 0;
while (i < 500) {
printf("\rThis is line number %d!", i++);
fflush(stdout); // <- add this call
}
return 0;
}
这篇关于CLion-回车吗? \r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!