I'm currently in the process of making Uno for a programming project. One part requires that I make the deck of 108 cards, where Card is its own class with a char color
and an std::string value
, the values of which I get from a file. I currently am just creating all 108 cards individually and then using push_back
to put them in the cards vector. Is there any way to more efficiently make the cards and put them into the vector? Currently it takes up 324 lines
Draw.cpp
#include "Pile.h"
#include "Draw.h"
#include "Card.h"
#include <iostream>
#include <fstream>
#include <string>
Draw::Draw(const std::string FILENAME)
{
std::ifstream inFile;
inFile.open(FILENAME);
if (inFile)
{
char newColor;
std::string newValue;
inFile >> newColor >> newValue;
Card card1(newColor, newValue);
this->cards.push_back(card1);
inFile >> newColor >> newValue;
Card card2(newColor, newValue);
this->cards.push_back(card2);
...
inFile >> newColor >> newValue;
Card card107(newColor, newValue);
this->cards.push_back(card107);
inFile >> newColor >> newValue;
Card card108(newColor, newValue);
this->cards.push_back(card108);
}
else
{
std::cout << "ERROR:" << std::endl;
std::cout << "The file " << FILENAME << " does not exist." << std::endl;
std::cout << "The deck cannot be created." << std::endl;
}
}