I have 2 enumerations of values for playing cards, their rank and suit. I want to take a file consisting of data like this:
2C 6D 7h 10s JC
This info determines a playing card.
6c is the 6 of clubs.
JC is the Jack of clubs, and so on. (Case does not matter).
How do I take the inputted characters and use them to make a new playing card? And having a case for every possible string seems like a lot of lines of code. Can that be simplified somehow?
#include "header1card.h"
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
Card card;
}
class Card {
private:
enum struct ranks {two, three, four, five, six, seven, eight,
nine, ten, jack, queen, king, ace };
enum struct suits {diamonds, clubs, hearts, spades };
suits su; //do what with these two?
ranks ra;
};
int fileparser(vector<Card> & readcards, char * filename) {
ifstream filereading;
filereading.open(filename, ios::in);
if (filereading.is_open()) {
//while read the file here. save what is read to a string.
char temp;
while (!filereading.eof()) {
//how make a card based off of the inputtedr chars?
char readchar = filereading.get(temp );
switch (readchar) {
case '2' :
break;
case '3' :
break;
//and so on to make every card? Seems like a lot of lines of code.
}
readcards.pop_back( /*After making the card, put it in vector*/ );
}
filereading.close();
}
else {
//throw error, cannot find file.
cout << "Could not find file " + filename << endl; //error on ' + filename'. Says Expression must have integral or unscoped enum type.
cerr << "COuld not find file " << endl;
}
}