C++ - Overloading <<

Hi All,

I have a problem whilst over-loading the << operator - I am developing in Visual Studio 2008. I have drop down boxes - lets call these 1,2,3. Now if you select 1,2,3 in that order they fill a List Box with lets say 4 differnt animals dog,cat,horse,tiger. If you select 3,1,2 then it will print 7 animals in the list box - this is just simple terms of what it does. So my class for the list box is called CProductListBox. In here i have overloaded the << operator as follows.

friend std::ostream& operator<< (std::ostream& o, const CProductListBox& b)
{
int count = b.GetCount();
for (int i = 0; i < count; ++i) {
CString text;
b.GetText(i, text);
o << (LPCTSTR)text << ",” << b.GetItemData(i) << endl
}

return o;
}

However it is not returning the list of items contained in the ListBox as I had hoped. Does anyone have any ideas/pointers (excuse the pun) as to something I may be missing - Cheers - Colly
Topic archived. No new replies allowed.