如何在cout末尾放置空格

问题描述 投票:0回答:2

我需要知道为什么 c++ 在 cout 函数末尾看不到空格。 我正在使用 CLion 和 C++ 23(语言标准)

int main()

{

    string Item ;
    double Price ;
    int Quantity ;
    double Total ;

    cout << "Your item to buy : " ;
    getline(cin, Item) ;
    cout << "Price of the item : " ;
    cin >> Price ;
    cout << "Quantity of the item : " ;
    cin >> Quantity ;

    cout << endl ;

    Total = Price * Quantity ;

    cout << "Item : " << Item << endl ;
    cout << "Price : " << Price << endl ;
    cout << "Quantity : " << Quantity << endl ;
    cout << "Total is : " << Total << endl ;

}

当我运行代码时,它返回我

Your item to buy :**HereIsNoSpace**
**HereIsSpace**Price of the item : 
**HereIsSpace**Quantity of the item :

所以我需要在“:”之后输入一个项目,而不是“:”

正如你所看到的,我的空格可能会在我的输入之后并传递到下一个字符串

c++ windows clion cout
2个回答
1
投票

显然解决方法之一是, 尝试执行以下操作:在注册表中(帮助 | 查找操作...,在其中键入注册表)禁用 run.processes.with.pty 选项并重新启动 CLion。这有帮助吗? 根据 CPP-12752 中的响应,禁用 PTY(无需重新启动 CLion,因为 CLion 重新启动后不会保存 run.processes.with.pty 选项 - CPP-8395)会有所帮助。

伙计们,我找到了这个问题的解决方案!


0
投票

当您使用 CLion 时,您可以尝试禁用 PTY(帮助 | 查找操作 > 键入“注册表” > 打开注册表 > 查找并禁用 run.processes.with.pty 选项) enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.