2016-03-31 7 views
-5

私はカードのデッキを使って構造体を作成したいと思いますが、私は顔とスーツの両方をint値にして呼び出しようとしているので、たとえばface = 3、suit = 1とすれば、Diamondsのうち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

あなたは答えをこのように得ることはありません。実際のエラーで既に試したことを示す –

+1

あなたはあなたの質問に答えたようです。あなたの提案されたアプローチが何らかの理由で動作していない場合は、それについて具体的に尋ねてください。 –

答えて

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]; 
} 
関連する問題