Cześć,
zrobiłem funkcje, którą robi to co opisałem w komentarzy do tego pytania. Może Ci to pomoże
void sum(HowManyPages p)
{
std::string line;
std::cout << "sum all pages \n";
std::ifstream outFile;
outFile.open("data.txt", std::ios::app);
if (outFile.is_open())
{
while (getline(outFile, line))
{
std::string token1 = line.substr(line.find(",")+1, line.length()-1);
std::string token2 = token1.substr(token1.find(":")+1, token1.length()-1);
p.pages = std::stoi(token2);
p.sum += p.pages;
}
outFile.close();
}
else
{
std::cout << "Unable to open file! \n";
}
std::cout << "Sum of pages : " << p.sum << std::endl;
}