不按我的要求显示数据输入表单
Does not show the data entry form as I want
我正在做一个简单的银行系统,在这个系统中我使用account creation
方法来创建新帐户
当客户输入时,要创建新帐户,他必须输入自己的个人数据
我知道这个问题既愚蠢又简单。
问题是当一个客户输入他的信息时,应该按如下方式显示数据。
-
您的名字:(并等待客户端输入)
-
您的姓氏:(并等待客户端输入)
-
您的年龄:(并等待客户输入)
-
您的地址:(并等待客户端输入)
上面发生的事情很自然,但发生的事情不是这样的。
发生的情况如下。
Your First name: (doesn't waits client inputs then continue ) Your last name: (and waits for client input).
Your age: (waits for client input) .
Your address: (doesn't waits client inputs then continue ) press any key to continue . . .
发生的情况与上图完全相同。
我没有放所有的代码,但我只添加了重要的代码。
// this struct to store the client information.
struct bc_Detail{
char cFistName[15];
char cLastName[15];
unsigned short usAge;
char cAddress[64];
};
// create an account
class Account_Create {
private:
int nAccountNumber; // account number
time_t nCreationDate; // date of join
int nBalance; // The amount of money
bc_Detail client; // instance of bc_Detail to store client info
public:
void createAccount(); // to create the account
};
// contents of create account method
void Account_Create::createAccount(){
std::cout << "Your First name: ";
std::cin.getline(client.cFistName, 15);
std::cout << "Your last name: ";
std::cin.getline(client.cLastName, 15);
std::cout << "Your age: ";
std::cin >> client.usAge;
std::cout << "Your address: ";
std::cin.getline(client.cAddress, 64);
}
int main(){
Account_Create create;
create.createAccount();
return 0;
}
尝试使用:
std::cin.get();// will eatup the newline
之后
std::cin >> client.usAge;
cin
存储在变量client.usAge
中输入的数字,提交条目所需的尾随换行符留在缓冲区中。
您也可以尝试:
cin.ignore();
问题是将对getline()的调用与">>":混合在一起
c++getline()不是';t多次调用时等待控制台输入
建议:
-
用">>"代替cin.getline()
-
同时,将"char-name[15]"替换为"std::string"。
-
还可以考虑用一个类来代替"struct bc_Detail"。
相关文章:
- c ++数据输入并读回列表中的结构结构中的数组
- 为什么我不能从结构将数据输入到字符数组中?
- C 如何忽略错误数据输入
- 如何在 C++ 中将结构类型向量数据输入到结构向量成员(嵌套结构向量)中
- 使用 for 循环多次将数据输入到 txt 文件
- C 从文本文件中将数据输入INT矢量
- 将数据输入两个字符串
- 带有 QSqlTableModel 的 QTableView 的数据输入
- C++用户将数据输入 2D 数组的最简单方法是什么?
- C++LinkedList数据输入
- 将数据输入到 2-D 数组中,这是如何工作的
- C++ 将数据输入私有向量时遇到问题(使用无效)
- 使数据输入字段记住其值,从一次运行到下一次运行
- C++ 将数据输入到用户定义类型的向量
- 我不知道如何正确地将数据输入到地图中
- 如何通过输入终止数据输入
- WHILE循环和数据输入
- 不按我的要求显示数据输入表单
- 用键盘将数据输入Qt GUI:按下回车键时会产生意想不到的副作用
- c++为不符合条件的数据输入创建循环