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;
nothing gets to the stream, though the temp has value;