I have this problem and need really fast solving. It's my code:
void stypendium() {
string tresc = "";
string temp;
stringstream ss;
fstream file;
vector<float> grades;
float grade, sum, av;
file.open(this->plik, ios_base::in);
if(!file.is_open()) {
ofstream fileTmp(this->plik);
fileTmp.close();
file.open(this->plik, ios_base::in);
}
while (file >> temp) {
if(strspn( temp.c_str(), "-.0123456789" ) == temp.size()) {
ss.str("");
ss << temp;
ss >> grade;
grades.push_back(grade);
}
};
sum = 0;
for(int i=0;i<grades.size();++i) {
sum += grades[i];
}
av = sum / grades.size();
cout << sum << "/" << grades.size() << "=" << av;
file.close();
}
};
Problem is that in line
ss << temp;
after first iteration nothing gets to the stream, though the temp has value
I might even say it's after second iteration, because first iteration gets the word and doesn't go into if statement, the second gets number and works with it properly. Next iterations gets temp value properly, but nothing gets to the stream.