I've been working on this project and this problem for a long time. I got understand the istream and ostream of classes well enough, my book is ****, this question will probably be simple for a c++ vet.
I have a class, customer. Its templated. Declare a varible of type customer(newCustomer). When I do cin >> newCustomer it goes through its routin about gathering info, like it should. In the istream function of the class I have it cout << some of the data the user just inputed (for a test). After the istream finishes it goes back to main, then I cout << newCustomer (another test). It prints out like it should except the user information is a bunch of null crap. Any idea whats going on? I just don't understand how c++ works.
Heres the code:
Important segment of main:
istream and ostream fnctions in customer class:Code:auto customer<void> newCustomer; cin >> newCustomer; cout << newCustomer; custTree.insert(newCustomer);
custTree is a tree data class. I'm sure it works as I got it from my teacher. The problem lies within myself.Code:template <class person> ostream & operator << (ostream &o, const customer<person> c) { o << c.ccNum << "\t" << c.fName << " " << c.lName << "\t" << c.status << "\t" << c.prevRentals << "\t" << c.cardDiscount << "\t" << c.prevRentDiscount << "\t" << c.fedTax << "\t" << c.netCost << "\t"; return o; } template <class person> istream & operator>> (istream i, customer<person> c) { auto int tempStatus = 3; cout << "Enter Credit Card #: "; i >> c.ccNum; cout << c.ccNum; cout << "Enter first name: "; i >> c.fName; cout << "Last name: "; i >> c.lName; cout << "1. Platinum 2. Gold 3. Regular\n"; cout << "Card status: "; i >> tempStatus; switch (tempStatus) { case 1: c.status = Platinum; c.cardDiscPerc = 0.06; break; case 2: c.status = Gold; c.cardDiscPerc = 0.03; break; default: c.status = Regular; c.cardDiscPerc = 0.0; break; } cout << "# of Previous Car Rentals: "; i >> c.prevRentals; cout << c.ccNum; return i; }
I will include a zip of my entire project if this for some reason isn't enough. Please keep in mind I'm new to C++.
Thanks to anyone who attempts this question!
NOMAD




Reply With Quote