lundi 31 juillet 2017

Error reading characters of string - for a string value in an array

I am trying to make a program that reads lines from a text files about information for a dvd. After feeding information to the custom dvd class, I am going to be printing it. Currently, when using debugger, it shows the below errors for each of the parameters of the custom class. Please help.

Error reading characters of string

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;

class dvd
{
    string movieName, movieProdComp, movieLeadActor, movieLanguage, renterName;
    string releaseYear, rentDate, returnDate;
public:
    dvd() {};
    dvd(string line) {};
    dvd(string mn, string mpc, string mla, string ml, string rn, string ry, string rd, string retd);
    void print();
};

dvd::dvd(string mn, string mpc, string mla, string ml, string rn, string ry, string rd, string retd) {
    movieName = mn;
    movieProdComp = mpc;
    movieLeadActor = mla;
    movieLanguage = ml;
    renterName = rn;
    releaseYear = ry;
    rentDate = rd;
    returnDate = retd;
}

void dvd::print() {
    cout << "Movie:" << movieName << endl;
    cout << "Production:" << movieProdComp << endl;
    cout << "Starring:" << movieLeadActor << endl;
    cout << "Language:" << movieLanguage << endl;
    cout << "Rented By:" << renterName << endl;
    cout << "Released:" << releaseYear << endl;
    cout << "Rent Date:" << rentDate << endl;
    cout << "Return Date:" << returnDate << endl;
}

int main() {
    string filepath = "C:\\Users\\SuperUser\\Google Drive\\COMP306\\TMA2\\test.txt";
    string line;
    ifstream file(filepath);
    string arrayDvd[10][8];
    if (file.is_open())
    {

        int i = 0;
        int c = 0;
        int n = 0;
        while (getline(file, line))
        {   
            arrayDvd[n][c] = line;
            i++;
            c++;
            if (i > 7)
            {
                n++;
                c=i = 0;
            }           
        }
    }

    for (int n = 0; n <= 9; n++) 
    {
        //this is where the error shows.
        dvd dvdS[] = { arrayDvd[n][0], arrayDvd[n][1], arrayDvd[n][2], arrayDvd[n][3], arrayDvd[n][4], arrayDvd[n][5], arrayDvd[n][6], arrayDvd[n][7] };
    }
}

Aucun commentaire:

Enregistrer un commentaire