connect vector<int> and vector<char>
So i wanted to create a deck and randomly deal it to user (13 cards). Then sort them in order from 1 to 13. The sorting function must also check to see if the card is heart, diamon.... in order to put them in front or behind.
i'm not sure if this is the fast way to do it, but i still give it a try. I started by create 2 vectors: one is int, one is char. The vector<int> will store four pairs of 1-13, and the vector<char> will store the simple of heart, diamond, club, and spade (13 pairs for each).
Code:
vector<int>CardNum;
vector<char>CardType;
char card[] = {'\03', '\04', '\05', '\06'}; //store the simples that will be push into the vector<char>
vector<int>myCard;
vector<char>myCardType;
void main()
{
int count=0;
srand(time(NULL));
for(int i=0; i<4; i++)
{
for(int j=1; j<=13; j++)
{
CardNum.push_back(j);
}
}
for(i=0; i<13; i++)
{
for(int j=0; j<4; j++)
{
CardType.push_back(card[j]);
}
}
for(int j=0; j<CardNum.size(); j++)
{
cout<<CardNum[j]<<CardType[j]<<" " ;
if(CardNum[j] == 13)
cout<<endl;
}
cout<<endl<<endl;
while(count != 13)
{
int getNum = rand()%12;
int getChar = rand()%3;
myCard.push_back(CardNum[getNum]);
CardNum.erase(CardNum.begin()+getNum);
myCardType.push_back(CardType[getChar]);
CardType.erase(CardType.begin()+getChar);
count++;
}
}
When an element in the deck's vector being push into the user's vector, that element will be delete out of the deck's vector. Now, if i want to sort the vector<int>, i have to somehow connect the vector<char> with it to. Can anyone help me with this.