passing std::array to a function

Trying to write a simple program that can successfully pass an std::array (card_deck) to a function (print_array). I don't know the parameters I should pass:

print_array(??)
{};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include <array>

using namespace std;

print_array( ?card_deck)
  {
	do stuff
  }

int main()
{
	int ctr(0);
	array<int, 52> card_deck;
	int ctr_1(0), loop(0);
	while (loop++ <4)
	{	ctr_1=1;
		while (ctr_1++ <13)
			{   //cout<<"loop val:"<<ctr_1;

				card_deck[ctr_1] = ctr_1;
				cout<<card_deck[ctr_1]<<"  ";
			}
	}
	return 0;
	}


How do I pass the std::array?
Last edited on
void print_array( std::array<int,52>& card_deck)
1
2
3
4
5
template <size_t N>
void print_array(const std::array<int, N> &array){
    for (auto &i : array)
        std::cout << i << std::endl;
}
If you want you can give the deck type an alternative name that is easier to remember.

 
typedef array<int, 52> CardDeck;

Then you can use that name instead of array<int, 52> everywhere.

1
2
3
4
5
6
7
8
9
10
void print_deck(const CardDeck& card_deck)
{
	// do stuff
}

int main()
{
	CardDeck card_deck;
	print_deck(card_deck);
}
Last edited on
Thx, all straightened out!
Topic archived. No new replies allowed.