473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

overloading ostream op in card class

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[i].setSuit(s);
deck[i].setRank(r);
deck[i].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[i] = deck2[random];
deck2[random].setPicked(true);
hand[i].printCard(out);
cout << endl;
}
}
}
//this worked, but it's not giving me random cards...pls i need help

Jul 22 '05 #1
1 1541
On 14 Dec 2004 10:21:07 -0800 in comp.lang.c++, "sahm" <ab*******@yahoo.com> wrote,
//this worked, but it's not giving me random cards...pls i need help


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

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Zenon | last post by:
Folks, I am having a terrible time overloading operators. I have tried what I thought was the correct way, I tried the cheating (friend declarations), all to no avail. Sorry for posting tons of...
3
by: Robert Wierschke | last post by:
Hi I want to overload the operator<< for a class Vector. class Vector { double x; double y; double z;
3
by: sahm | last post by:
i need help to use this function, but use an overloaded operator<< instead.... ostream operator<<(ostream& out, vector<Card>& deck) { int i = 0; for (int s = 1; s <= 4; s++) { for (int r = 1;...
1
by: sahm | last post by:
hi, i have to create a program that will print the 52 cards in a deck using the overloaded ostream operator. it worked fine....then i hve to create a function that will print the cards in hand in...
5
by: Banshee | last post by:
Hi there, I tried with Visual C++ 6.0 to overloading the ostream operator for an object. While compiling I receive this error: Compiling... main.cpp C:\\main.cpp(8) : error C2678: binary...
8
by: jois.de.vivre | last post by:
Hi, I'm having some trouble overloading the << operator. I have the following, very simple code: #include <iostream> using namespace std; class test { private: int val;
7
by: John | last post by:
I always understood that in C++, if I said a + b a.operator+(b) is called. Now this makes sense with the operator<< when used in the following way cout << 100; // converts to ...
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.