dimanche 3 février 2019

Is this the right way to read a file input?

Is this the right way to read a line from a file, split it into 2 variables(a text and an answer), and then feed those two variables into a vector of a class I created?

example being if i had a text file with a list of questions and answers, would this be how I read each question and answer being on one line together "12 How many inches in a foot?"

void LoadQuestions(){
    std::string blank;
    std::string text;
    std::string answer;
    std::string line;

    while (std::getline (questionsFile, line ) {
    std::stringstream ss(line);
    ss>>answer>>blank;
    getline(ss, text);
    questions.Question(text, answer).push_back();
    if (questionsFile.eof()){
            break;
            }
    }
questionsFile.close();
}

Aucun commentaire:

Enregistrer un commentaire