我有这两个数组:
const char *face[] =
{"Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King", "Ace", "\0"};
const char *suit[] = { " of Hearts", " of Clubs", " of Diamonds", " of Spades", "\0" };
实际上,由于我在 C++ 中什至不是那么好,所以我什至不知道您何时在数组或其他任何地方使用星号......如果有人也能解释一下,我将不胜感激。
但无论如何,问题是我试图用他们的西装打印出所有可能的卡片,如下所示:
for (int n = 0; n<strlen(*suit); n++){ //where strlen(*suit) should be 4
for(int i = 0; i<strlen(*face); i++){ //where strlen(*face) should be 13
cout << endl << face[i] << suit[n] << endl;
}
}
使用该代码,我的程序崩溃了。我究竟做错了什么?(它在使用 n<4 和 i<13 时有效,但如果我从数组中添加或删除项目,我希望它实际工作)