samedi 3 novembre 2018

Defining a constant by a variable in C++

So I need to define a constant by a variable so I can use that value in the definition of an array. Will this work?

std::fstream scores("scores.txt");
int numberOfLines;
std::string temp;

while (std::getline(scores, temp))
{
    numberOfLines++;
}

const int numberOfLines1 = numberOfLines;
int scoresArr [numberOfLines1] = {};
scores.close();

Aucun commentaire:

Enregistrer un commentaire