0
我想在用户输入后直接添加百分号(以便用户不必输入百分号)。当我尝试这个时,它要么到达下一个线路,要么根本不工作。如何在C++后直接添加字符(cin)
我想要什么: _%
//空白是供用户输入的。
对不起,如果这是混乱的,我不知道如何添加C++在这里。
这里有一些事情我曾尝试:
// used a percent as a variable:
const char percent = '%';
cout << "Enter the tax rate: " << percent; // obviously here the percent
symbol goes before the number.
double taxRate = 0.0;
cin >> taxRate >> percent; // here I tried adding it into the cin after the cin.
cin >> taxRate >> '%'; // here I tried adding the char itself, but yet another failed attempt...
那么,它甚至有可能做我想要什么?
这是不可能的(或可取的)。而iostream库并非真正用于交互式使用。 –
很好,这正是我们在学校学习的内容,所以我想让自己对我自己的用户友好,我猜... – hannacreed
不要浪费你的时间 - 这是不能做到的。 –