Was it necessary to make an array like this?

Ive never been great with arrays. Ive made this array to make 52 cards (for my poker game im making). I feel like there is a much easier way I could have done this instead of having to make 52 lines of cards[0]="Card\n";. Also whats the point of arrays? Couldn't you just use vectors? They get the special functions like size, erase, length, random_shuffle, iterators, clear, empty, ect. I just dont get the point of using arrays.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 #include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
string cards[52];

cards[0]= "Ace\n";
cards[1]= "Ace\n";
cards[2]= "Ace\n";
cards[3]= "Ace\n";
cards[4]= "Two\n";
cards[5]= "Two\n";
cards[6]= "Two\n";
cards[7]= "Two\n";
cards[8]= "Three\n";
cards[9]= "Three\n";
cards[10]= "Three\n";
cards[11]= "Three\n";
cards[12]= "Four\n";
cards[13]= "Four\n";
cards[14]= "Four\n";
cards[15]= "Four\n";
cards[16]= "Five\n";
cards[17]= "Five\n";
cards[18]= "Five\n";
cards[19]= "Five\n";
cards[20]= "Six\n";
cards[21]= "Six\n";
cards[22]= "Six\n";
cards[23]= "Six\n";
cards[24]= "Seven\n";
cards[25]= "Seven\n";
cards[26]= "Seven\n";
cards[27]= "Seven\n";
cards[28]= "Eight\n";
cards[29]= "Eight\n";
cards[30]= "Eight\n";
cards[31]= "Eight\n";
cards[32]= "Nine\n";
cards[33]= "Nine\n";
cards[34]= "Nine\n";
cards[35]= "Nine\n";
cards[36]= "Ten\n";
cards[37]= "Ten\n";
cards[38]= "Ten\n";
cards[39]= "Ten\n";
cards[40]= "Jack\n";
cards[41]= "Jack\n";
cards[42]= "Jack\n";
cards[43]= "Jack\n";
cards[44]= "Queen\n";
cards[45]= "Queen\n";
cards[46]= "Queen\n";
cards[47]= "Queen\n";
cards[48]= "King\n";
cards[49]= "King\n";
cards[50]= "King\n";
cards[51]= "King\n";

}
Your guess is as good as mine.. Arrays are pretty much pointless to me too, but teachers still teach them. I would only use vectors
You can use a lookup table, and then use a loop to fill your array:

1
2
3
4
5
6
7
const char* const cardname_lut[13] = 
{"Ace\n","Two\n","Three\n","Four\n","Five\n","Six\n",
"Seven\n","Eight\n","Nine\n","Ten\n","Jack\n","Queen\n","King\n"};

std::string cards[52];
for(int i = 0; i < 52; ++i)
    cards[i] = cardname_lut[i/4];
Topic archived. No new replies allowed.