Using Visual Studio 2008...My assignment is to use the file SalesData.txt to load an array of structs, and use the array of structs to show to the screen a control-break report which breaks with each change in salesperson and shows each salesperson's total sales. I have not finished but I keep getting this error:

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)

This is what I have so far, but I can't get pass the error:

#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)
{is >> purchase.name >> "\t" >> purchase.type >> "\t" >> purchase.style >> "\t" >> purchase.price >> "\t" >> purchase.quantity;
return is;}

int main()
{
ifstream indata;//input file stream
indata.open("SalesData.txt");
salesTran purchase[75];
int subtotal=0;

	for(int x=0;x<75;x++)//input loop
	{
		indata>>purchase[x];
	}

	for(int y=0;y<75;y++)//compute & output loop
	{
	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;
}

line 19: >> "\t" YOu can't do that with input streams. If the fields are separated by tabs and do not contain any spaces then istream will auto skip the tabs. If there are any spaces in the fields then you can't use >> operator, but must use getline(), such as getline(is, purchase.name,'\t'); Also the parameter to that overloaded >> operator needs to be an reference to the salesTran object, like this: istream& operator >> (istream& is, salesTran& purchase)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.