我整个早上都在尝试打印出我的 m_deck 中的卡片,共 13 行 4 列,但我一辈子都无法弄清楚。目前它仅在一栏中打印。我正在使用 CLion。我真的需要一些帮助来解决这个问题。谢谢!
Deck.cpp
void Deck::show() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
m_deck[i * 13 + j].show();
cout << " ";
}
cout << "\n";
}
};
卡片.cpp
void Card::show() {
...
cout << m_rank << " of " << m_suite << ": " << rank << suite << "\n";
};
尝试:
void Deck::show() {
static constexpr unsigned rowCount = 13;
static constexpr unsigned columnCount = 4;
// Iterate the 13 rows
for (auto i = 0; i < rowCount; i++) {
// Iterate trough the columns
for (auto j = 0; j < columnCount; j++) {
m_deck[i * columnCount + j].show();
cout << " ";
}
cout << "\n";
}
};