I want to select certain strings from lines of a data file. The data file is called "Games.dat" and here is the information it contains:
Snake, Solid, Metal Gear Solid, 9/3/1998, 94, Konami
Drake, Nathan, Uncharted, 11/19/2007, 90, Naughty Dog
Guy, Doom, Doom, 5/13/1993, 95, iD
The data is organized by:
Character Last Name, First Name, Game Name, Relase Date, Score, Developer
I am wanting to create a list that displays only the Developer, Release Date, and Score in that order.
Here is my code so far:
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
using namespace std;
ifstream inFile;
class Dev{
private:
string Developer;
public:
Dev(){};//null constructor
void printDeveloper(){
cout<<"Developer: "<<Developer<<endl;
}
void getDeveloper(){
if(inFile.is_open()){
getline(inFile, Developer, ',');
} else {
cout<<"Nothing here..."<<endl;
}
}
};
class RelDate_And_Score{
private:
string ReleaseDate;
string Score;
public:
RelDate_And_Score(){};
void GetRelDate(){
if(inFile.is_open()){
getline(inFile, ReleaseDate, ',');
} else{
cout<<"Could not find Release Date"<<endl;}
}
void getScore(){
if(inFile.is_open()){
getline(inFile, Score, ',');
} else{
cout<<"Could not find Score"<<endl;}
}
void PrintDate(){
cout<<"Release Date: "<<ReleaseDate<<" | ";}
void PrintScore(){
cout<<"Score: "<<Score<<endl;}
};
int main(){
inFile.open("Games.dat");
Dev d;
d.getDeveloper();
d.printDeveloper();
RelDate_And_Score r;
r.GetRelDate();
r.getScore();
r.PrintDate();
r.PrintScore();
return 0;
}
The output I am getting:
Developer: Snake
Release Date: Solid | Score: Metal Gear Solid
Any help would be greatly appreciated!