输出字符串末尾的空白不与字符串一起打印,而是与它后面的下一个打印行一起打印 [英] White space on the end of output string not printing with the string, but rather with the next printed line after it

查看:50
本文介绍了输出字符串末尾的空白不与字符串一起打印,而是与它后面的下一个打印行一起打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打印一条行,要求用户输入,获取输入,然后再次打印一些行.问题是,在我得到输入之后,第一条打印行末的空白不是在行末打印,而是在第二条打印行的开始打印.

I tried to print a line that asks for input from the user, get the input, then print again some line. The problem is that the white space at the end of the first printed line is printed not at the end of the line, but rather at the beginning of second printed line, after i get the input.

我对C ++完全陌生,所以我不能做太多尝试,但是我尝试在没有提示用户输入的部分的情况下打印代码,并且可以很好地打印空间,但是当我添加 std :: cin<<输入; 空格被发送到第二行的开头.

I'm completely new to C++ so I couldn't really try much, but i tried printing the code without the part that prompts the input from the user, and it prints the space just fine, but when i add std::cin << input; the space get's sent to the beginning of the second line.

我的代码:

    int input;
    std::cout << "Enter your favorite number between 1 and 100: ";
    std::cin >> input;
    std::cout << "Amazing... That's my favorite number too... wow..." << std::endl;

我希望输出为

Enter your favorite number between 1 and 100: //some input
Amazing... That's my favorite number too... wow...

(请注意//某些输入之前的空格)

反而我得到

Enter your favorite number between 1 and 100://some input
 Amazing... That's my favorite number too... wow...

(请注意 Amazing 之前的空格)

如果可以连接,我正在使用Clion.另外,我尝试在Powershell上运行可执行文件,并且按预期方式运行,没有出现问题,因此这与Clion终端有关.另外,我将Windows 10用作操作系统.

I'm using Clion if it could be connected. Also, I tried to run the executable on powershell and it worked as expected, without the problem, so this has something to do with the Clion terminal. Also, i'm using windows 10 as my OS.

第二次修改:将我的发现添加到我的答案中.

Second add my findings on my answer.

推荐答案

这似乎与Clion的缓冲输入有关.看到此问题: https://youtrack.jetbrains.com/issue/CPP-7437

This seems to be a problem with buffered input of Clion. See this issue: https://youtrack.jetbrains.com/issue/CPP-7437

这篇关于输出字符串末尾的空白不与字符串一起打印,而是与它后面的下一个打印行一起打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆