For loop should iterate through std::vector and populate content.
First for loop gives me an error message saying:
NO BINARY OPERATOR FOUND << No convert possible
vector<MyClass>classVector;
for (vector<MyClass>::iterator i = classVector.begin();
i != classVector.end();
++i)
{
cout << *i << endl;
}
MyClass.h:
class MyClass{
private:
string newTodayTaskString;
public:
MyClass(string t) : newTodayTaskString (t){}
~MyClass(){}
};
This for loop iterates through a vector of strings and works perfectly. Why?
vector<string>stringVector;
for (vector<string>::iterator i = stringVector.begin();
i != stringVector.end();
++i)
{
cout<<*i<<endl;
}
You need to overload the stream operator for your class if you want to be able to directly call
std::cout::operator <<.You can either define it as:
and declare this operator as friend so it has access to the private members of the class or provide a print function to your class and use that instead.