我需要知道为什么 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 :
所以我需要在“:”之后输入一个项目,而不是“:”
正如你所看到的,我的空格可能会在我的输入之后并传递到下一个字符串
显然解决方法之一是, 尝试执行以下操作:在注册表中(帮助 | 查找操作...,在其中键入注册表)禁用 run.processes.with.pty 选项并重新启动 CLion。这有帮助吗? 根据 CPP-12752 中的响应,禁用 PTY(无需重新启动 CLion,因为 CLion 重新启动后不会保存 run.processes.with.pty 选项 - CPP-8395)会有所帮助。
伙计们,我找到了这个问题的解决方案!