我想创建一个带有卡片组的结构但是我不知道我该怎么做,因为我试图使face和suit都成为int值并且在调用时face = 3 and suit = 1它会给我:3颗钻石。这样的事情。帮助将不胜感激..谢谢你有美好的一天!
#include <iostream>
#include <cmath>
using namespace std;
struct cards {
char suit[];
};
int main() {
cards type = {
'0','1','2','3','4'
};
cout << type.suit << endl;
}
我知道这是错的,我不知道该怎么做......
答案 0 :(得分:0)
来自原始代码:
const std::string suit[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
const std::string facevalue[] = {
"Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"
};
struct card
{
card(int index)
: suit(index % 4)
, rank(index % 13)
{}
int suit;
int rank;
};
std::ostream& operator<<(std::ostream& os, const card& c)
{
return os << facevalue[c.rank] + " of " + suit[c.suit];
}