【发布时间】:2018-02-22 15:16:36
【问题描述】:
我试图在用户输入后直接添加一个百分号(这样用户就不必键入百分号)。当我尝试这个时,它要么转到下一行,要么根本不起作用。
我想要什么: _%
// 空白用于用户输入。
对不起,如果这很混乱,我不知道如何在这里添加 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 库并不是真正用于交互式使用的。
-
好吧 idk,这正是我们在学校学习的内容,所以我想我想使它对自己用户友好......
-
不要浪费你的时间 - 这是不可能的。
-
你必须放弃
cin并使用类似curses 库的东西。尼尔·巴特沃思拥有它的权利。除非作业要求,否则你最好把时间花在可以提高成绩的事情上。
标签: c++ windows visual-studio window