getline overloaded? helppp


"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;
}
so what should i do?

i tried adding
getline(is,str);
and
istream::getline instead of
istream
but it doesnt work
getline takes a string as an argument. If your variable is not a string, you can't use getline.
Try using operator >>:
1
2
3
4
5
6
7
8
9
istream& operator >> (istream& is, salesTran& purchase)
{
    getline(is, purchase.name,'\t');
    getline(is, purchase.type,'\t');
    getline(is, purchase.style,'\t');
    is >> purchase.price;
    is >> purchase.quantity;
    return is;
}
Topic archived. No new replies allowed.