我正在尝试使用循环创建变量名。
具体来说,我正在使用这种结构:
struct card{
string rank;
string suit;
};
这是我的代码的其余部分,它说“card + i”是我需要它说“card1”或“card2”等的地方。
string aSuit[4] = {" Hearts"," Clubs"," Diamonds"," Spades"};
string aRank[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
string aDeck[52];
int main(int argc, char *argv[])
{
int i = 0;
for (int s=0; s<4; s++) {
for (int r=0; r<13; r++) {
card card+i;
card+i.rank = aRank[r];
card+i.suit = aSuit[s];
cout << card + i.rank << card + i.suit << endl;
i++;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}