overloading ostream op in card class

S

sahm

hi,
i created a function
ostream& operator<<(ostream& out, vector<Card>& deck)
{
int i = 0;
for (int s = 1; s <= 4; s++)
{
for (int r = 1; r <= 13; r++, i++)
{
deck.setSuit(s);
deck.setRank(r);
deck.printCard(out);
}
out << endl;
system("pause");
out << endl;
}
return out;

}
//that will print out the ordered deck of cards, i need to create a
function that will overload ostream operator, and that will print out
the cards in the hand in random order(ranges 5 to 15)...
void fillHand(ostream& out, vector<Card>& hand, vector<Card>& deck2)
{
for(unsigned int i = 0; i < hand.size(); i++)
{
int random;
random = randNum(0, 51);

if(deck2[random].isPicked())
{
deck2[random].printCard(out);
cout << endl;
int last = hand.size() - 1;
hand.push_back(hand[last]);
for(int i = last; i > deck2[random].isPicked();
i--)
{
hand[last] = hand[last - 1];
}

}

else
{
hand = deck2[random];
deck2[random].setPicked(true);
hand.printCard(out);
cout << endl;
}
}
}
//this worked, but it's not giving me random cards...pls i need help
 
D

David Harmon

On 14 Dec 2004 10:21:07 -0800 in comp.lang.c++ said:
//this worked, but it's not giving me random cards...pls i need help

#include <algorithm>
std::random_shuffle(deck.begin(), deck.end());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top