0

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!

brrnrr_47
  • 13
  • 5
  • 2
    It really looks like [this](http://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c) is what you need. – NathanOliver Oct 14 '16 at 17:55
  • Off topic: `if(inFile.is_open())` is missing a lot of other things that can go wrong with a file. `if(inFile)` will catch pretty much all of them. [Detailed documentation on how this works.](http://en.cppreference.com/w/cpp/io/basic_ios/operator_bool) – user4581301 Oct 14 '16 at 18:09

0 Answers0