Sunday, December 28, 2025

C++ Cards

A Deck of Cards 

C++ example of a deck of cards.

Output to stdout. From here you can do a shuffle, deal, whatever with the deck. Poker, BlackJack, Solitare.







//------------------------cards.cpp
#include <stdio.h>
#include <strings.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>

using namespace std;
void unwrap(vector<int> &);
void shuffle(vector<int> &);
void printCards(const vector<int> &);

vector<string> suit = {" \033[1;31m\342\231\241\033[0m", " \342\231\247", " \033[1;31m\342\231\242\033[0m", " \342\231\244"};
vector<string> value = {"2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10 ", "J ", "Q ", "K ", "A "};

int main()
{
    int index = 0;
    //print to screen
    for (string s : suit)
        {
        for (string v : value)
            {
            cout << s << v;
            index++; 
            }
        cout  << index <<"\n";
        }

cout << "\n";                   //space
index = 0;
                      //reset

  return 0;
}//EOF

No comments:

Post a Comment