我有以下代碼。我想用一副紙牌填充一個數組,並且不管我如何編寫循環來填充數組,我都會遇到同樣的錯誤「期望的表達式錯誤」。Structs數組(預期的表達式錯誤)C++
任何人都可以看到我要去哪裏錯了。我認爲它的東西非常簡單,我剛剛缺少C++的新手。
謝謝!
#include <iostream>
using namespace std;
struct playingCard{
char suit; // heart (1), club (2), spade (3), diamond (4)
int value; // 1 to 13 (ace is LOW)
};
void printArray(playingCard playingCardArray[], int size){
for (int i = 0; i < size; i ++){
cout << playingCardArray[i].suit << ":\t" << playingCardArray[i].value << endl;
}
}
int main()
{
const int ARRAY_SIZE = 52;
playingCard playingCardArray[ARRAY_SIZE];
int i = 1;
int suitLoop = 1;
while (suitLoop == 1){
for (int valueLoop = 1; valueLoop <= 13; valueLoop++){
playingCardArray[i] = {suitLoop, valueLoop},
}
}
printArray(playingCardArray, ARRAY_SIZE);
return 0;
}
'playingCardArray [i] = {suitLoop,valueLoop},'應該以';'結尾而不是逗號。你的錯誤信息沒有提到錯誤發生的路線? – Borgleader 2014-09-25 18:43:00