Printing out the contents of a vector of structs

I am creating a deck of cards using a vector of structs containing the suit and rank of a card.

1
2
3
4
5
struct aCard
  {
	  int Suit;
	  int Rank;
  };


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Deck::initialiseDeck()
{
	int x = 0;
	int y = 0;
		for(y = 0; y < 4; y++)
		{
			for(x = 0; x < 13; x++)
			{
				aCard c;
				c.Suit = y;
				c.Rank = x;
				Cards.push_back(c);
			}
		}
}


I want to test that the function initisaliseDeck has created my vector of cards so im trying to print out the contents of the the vector, however i have no clue as of how to do this. C

Can someone please enlighten me?

All help is greatly appreciated =)
for (int i = 0; i < 13*4; i++) cout << Cards[i].Suit << ", " << Cards[i].Rank << "\n";

Write a constructor for aCard (or at least a function aCard makeCard(int, int); if you're not familiar with constructors yet) to make initializeDeck() cleaner. It will then only need one pair of {} and five ;s (even though you could minimize it to 3 ;s, that would not be of much use, I think). This might be a good exercise for you (so that you know what can be removed).
Thanks for your help i had something similar to that in my head =)
Topic archived. No new replies allowed.