views:

36

answers:

1

This problem is annoying me. Instead of waiting for input, it just closes. I've been trying to figure this out for a while now. Any ideas?

    istream& operator>>(istream& is, Account &a) {
    cout << "Enter an accoutn number: ";
        is >> a.accountNo;
        cout << endl;
    cout << "Balance: ";
        is >> a.bal;
    return is;
    }
A: 

When I put it into the following program, it worked fine (though it wouldn't work so well if you tried to read an account from anything but 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;
}
Jerry Coffin