Reputation: 3126
So, I am trying to simply print the content of the vector that I am creating. Essentially I am trying to output the player which would be an int (i.e. 1-4) and the player's hand which consists of Card objects. So, for example, I am trying to get it to the point where newPlayerHand[1][1] will give me "Ace of Spades", and newPlayerHand[1][2] will output "Jack of Clubs"
void Blackjack::deal()
{
// create a new hand
vector < vector < Card >> newPlayerHand;
for (int i = 0; i < numPlayers; i++)
{
vector < Card > player; // Create an empty row
for (int j = 0; j < 2; j++) {
player.push_back(dealCard()); // Add an element(column)
// to the row
newPlayerHand.push_back(player); // Add the row to the main vector'
cout << newPlayerHand[i][j];
}
}
}
The above code looks and sounds correct logically to me, but it is giving me the error "No such operator <<" when I am attempting
cout << newPlayerHand[i];
Any advice or tips on where I am going wrong here would be greatly appreciated.
Ok, so I have edited it to account for the ostream operator, but I still seem to be getting an error for unresolved external. (basic_ostream)
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
return os;
}
Upvotes: 0
Views: 111
Reputation: 296
Your problem is not with Vectors. Its with this line of code.
cout << newPlayerHand[i][j];
When you do the above step the object to be output is of data type card. "<<" ostream operator knows how to display basic data types not data types created by us. So provide it with proper structures to output value of card data type and you can proceed.
Upvotes: 1