Witam. Mam do napisania program, który policzy średnią i odchylenie standardowe wczytanych wartości z pliku(chodzi o wartości strat). Niestety chcąc najpierw wyświetlić wszystkie wyszukane wartości, program w pewnym momencie wyrzuca błąd i nie mam pojęcia o co chodzi.
#include <iostream>
#include <ctime>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream plik;
string txt;
string liczba;
string txt2;
int x;
int i;
int flag = 1;
plik.open("logowanie.txt");
if (plik.good() == true) {
cout << "Uzyskano dostep do pliku!" << endl;
while (getline(plik, txt)) {
if (txt.find("loss") != string::npos) {
x = txt.find("loss");
x = x + 7;
txt.erase(0, x);
txt.erase(6, x);
cout << txt << endl;
txt.clear();
txt = "";
}
}
}
else cout << "Nie mozna otworzyc pliku" << endl;
system("pause");
}