dimanche 13 mai 2018

Taking a substring from a text file

I'm working on a movie list from a text file that looks like that:

105715::Just Wright (2010)::2.00
96616::That's My Boy (2012)::2.25
127096::Project Almanac (2015)::2.50
5418::Bourne Identity, The (2002)::3.88
1615::Edge, The (1997)::3.65

The first numbers are my movieId and I'm trying to take it as a substring.

void BSTMovieFinder::appendMovies(string filename) {
    ifstream myReadFile(filename);
    string readMovie;

    while (!myReadFile.eof()) {
        getline(myReadFile,readMovie);
        cout << readMovie << endl;
        this->movieId = stoi(readMovie.substr(0, readMovie.find(":")));
        cout << this->movieId << endl;
    }
}

Somehow, it doesn't work properly. When I execute this code it stops at the end and netbeans debugger send this error message:

(Unrecognized or ambiguous flag word "?")

Aucun commentaire:

Enregistrer un commentaire