Connecting Tech Pros Worldwide Forums | Help | Site Map

reading from infile

Newbie
 
Join Date: Sep 2006
Posts: 7
#1: Dec 8 '06
I am confused about looping through an infile for my homework.

in my header file I have:

class Item
{
friend istream& operator>>(istream&, Item&);
public:
void print() const;
Item(string *p, string *d, double *pr);
private:
string *part;
string *deptNo;
double *itemPrice;
};

in my cpp file I have:

Item::Item(string* p, string* d, double* pr)
{
part = p;
deptNo = d;
itemPrice = pr;
}

Then in my file I have:

void readDataItem(istream& in, string& partNum, string& dept, double& price);

int main()
string partNum;
string dept;
double price;

string inputFileName = "input.txt";
string sortFileName = "sorted.txt";

ofstream outData;
ifstream inData;

inData.open(inputFileName.c_str());

while (!inData.eof())
{
readDataItem(inData, partNum, dept, price);

Now, I'm stuck. I thought I could use an array since I have pointers, but I can't figure out how to do it. If I cout<<inData, I get 0s and each individual item doesn't give me anything, but all 3 together gives me an endless loop. If I could just get the next couple of steps, I could finish this homework, but I'm stuck right here. Please help..

Reply