| nickdalal (6) | |
|
"getline error: no instance of overloaded function "getline" matches argument" i keep getting that error and when i take out "getline(is, purchase.price,'\t'); getline(is, purchase.quantity,'\t');" it works fine #include <iostream> #include <fstream> #include <string> using namespace std; struct salesTran { string name; string type; string style; double price; double quantity; }; ostream& operator << (ostream& os, salesTran purchase) {os << purchase.name << "\t" << purchase.type << "\t" << purchase.style << "\t" << purchase.price << "\t" << purchase.quantity; return os;} istream& operator >> (istream& is, salesTran& purchase) {getline(is, purchase.name,'\t'); getline(is, purchase.type,'\t'); getline(is, purchase.style,'\t'); getline(is, purchase.price,'\t'); getline(is, purchase.quantity,'\t'); return is;} int main() { ifstream indata; indata.open("TRAN3.DAT"); salesTran purchase[75]; int subtotal=0; for(int x=0;x<75;x++) { indata>>purchase[x]; } for(int y=0;y<75;y++) { cout << purchase[y].name; cout << purchase[y].type; cout << purchase[y].style; cout << purchase[y].price; cout << purchase[y].quantity; } for(int z=0;z<75;z++) { cout << purchase[z]; cout << "\t" <<purchase[z].quantity*purchase[z].price << endl; } indata.close(); return 0; } | |
|
|
|
| coder777 (2378) | |
|
See: http://www.cplusplus.com/reference/string/getline/ it takes string only | |
|
|
|
| nickdalal (6) | |
|
so what should i do? i tried adding getline(is,str); and istream::getline instead of istream but it doesnt work | |
|
|
|
| toum (169) | |||
|
getline takes a string as an argument. If your variable is not a string, you can't use getline. Try using operator >>:
| |||
|
|
|||