operator >>??

Hi everyone?

I am working on an struct inventory,

I have a function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// I have a vector because that is where I stored the file I read
ostream& operator << (ofstream& out, vector<Inv>& V)
{
vector<Inventory>::iterator vIter;
	
for (vIter = V.begin(); vIter<V.end(); vIter++)
{
     out << vIter->name << " " << vIter->price	
}	
return out;
}

// now how do I call this in main() or anothe function()
int main()
{
  vector<Inv> V;

  cout << V;// why wont this work??
}

// or
void something(vector<Inv>& V)
{
  cout << V;// why wont this work??
}


I hope I amking it kind of clear where my confusion is.

Anyone with some help or advise?

Thanks in advance
Is Inventory the same type as Inv?

You forgot a semicolon on line 8.
cout is not an ofstream, it's ostream. 'f' for 'file'. If you fix that, I think it should be okay. Except for missing ; on line 8.
Topic archived. No new replies allowed.