放置在结构中的一副牌
Deck of Cards placed in structs
我想创建一个结构,里面有一副牌,但我不知道该怎么做。由于我试图使两个面都适合int
值,因此当调用例如face = 3
和suit = 1
时,它会给我:3 of Diamonds。
#include <iostream>
#include <cmath>
using namespace std;
struct cards {
char suit[];
};
int main() {
cards type = {
'0','1','2','3','4'
};
cout << type.suit << endl;
}
我知道这是错误的,我不知道该怎么做。。。
来自您的原始代码:
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];
}
相关文章:
- 在 c++ 中拥有一组结构的正确方法是什么?
- 使用一组结构,避免在一组结构中出现重复的结构
- 初始化一副牌C++
- 将一副牌循环100次(一副牌)
- 在 c++ 中将一种结构类型分配给另一种类型
- 动态分配一维结构数组:两种方法
- 将指向结构的指针转换为具有较少字段数的另一种结构类型
- 链表一副牌,只出现51张牌,没有出现52张
- 一组结构缺少元素
- 在一副牌上得分
- 我们如何才能只初始化一次结构成员,并确保它们不可变
- 放置在结构中的一副牌
- 使用向量c++存储和洗牌一副牌
- C++ - 使用枚举生成一副纸牌
- 我需要帮助在C++中生成一副纸牌
- 如何在c++中生成一副牌
- 制作一组结构
- 如何初始化一副纸牌的 3D 数组
- 从一副牌中发牌(不重复的牌)
- 制作一副纸牌