这个问题让我很烦。它不等待输入,而是关闭。我一直试图弄清楚这一点。有任何想法吗?
istream& operator>>(istream& is, Account &a) {
cout << "Enter an accoutn number: ";
is >> a.accountNo;
cout << endl;
cout << "Balance: ";
is >> a.bal;
return is;
}
这个问题让我很烦。它不等待输入,而是关闭。我一直试图弄清楚这一点。有任何想法吗?
istream& operator>>(istream& is, Account &a) {
cout << "Enter an accoutn number: ";
is >> a.accountNo;
cout << endl;
cout << "Balance: ";
is >> a.bal;
return is;
}
当我将它放入以下程序时,它运行良好(尽管如果您尝试从除std::cin
.
#include <iostream>
struct Account {
int accountNo;
int bal;
};
using std::ostream;
using std::istream;
using std::cout;
using std::endl;
istream& operator>>(istream& is, Account &a) {
cout << "Enter an account number: ";
is >> a.accountNo;
cout << endl;
cout << "Balance: ";
is >> a.bal;
return is;
}
ostream &operator<<(ostream &os, Account const &a) {
return os << "Account #: " << a.accountNo << "\tBalance: " << a.bal;
}
int main() {
Account a;
std::cin >> a;
std::cout << a;
return 0;
}