I'm writing a server software with an onboard database using MS VC++2008 Express. Right now, it's the latter part that has me a bit stumped. I've created a class for a User, and I'm instantiating it through a vector. The problem is that one of the attributes of the class is a vector itself, and therefore its accessor is a vector, too. When I try to use cout to print it out, I get this:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
TBH, I'm not even sure that my accessor will do what I want it to do, but at least it compiles if I don't try to call it. Here's my whole code so far:
I've tried calling it with the other accessors, and it works just fine, so it's not a namespace issue.
// The main file
#include "User.h"
// Function Prototype
void makeDataBase();
int main()
{
// First create the database
makeDataBase();
system("pause");
return 0;
}
/*********************************************************************
* Definition of function makeDataBase *
* This function instantiates a vector of User objects. In this *
* way, it can be searched and sorted. For test purposes, the *
* vector will be initialized with three addresses. It will first *
* call the default constructor, then call each mutator function for *
* each attribute. Other portions of this function are temporary for *
* testing the accessors. *
*********************************************************************/
void makeDataBase()
{
constint NUM_USERS = 3;
vector<User> userDataBase(NUM_USERS);
for(int count = 0; count < NUM_USERS; count++)
{
userDataBase[count] = User();
}
userDataBase[0].setUserNumber("000000");
userDataBase[0].setUserName("Admin");
userDataBase[0].setPassword("password");
userDataBase[0].setFriendList(2, "Seymour Butts", "Ben Dover");
userDataBase[1].setUserNumber("000001");
userDataBase[1].setUserName("Seymour Butts");
userDataBase[1].setPassword("booger");
userDataBase[1].setFriendList(2, "Admin", "Ben Dover");
userDataBase[2].setUserNumber("000002");
userDataBase[2].setUserName("Ben Dover");
userDataBase[2].setPassword("snotty");
userDataBase[2].setFriendList(2, "Seymour Butts", "Admin");
for (int count = 0; count < NUM_USERS; count++)
{
cout << userDataBase[count].getFriendList() << endl;
}
}
Does anyone have any suggestions on how to resolve this error? I'm thinking I might need to overload the '<<' operator, but I'm not sure how I'd go about doing that properly. Thank you for your help in advance.