#include<vector>// i dont want to use this !!!
class FileManager{
public:
vector<Utilizator> readUsers(char* filename){
ifstream f(filename);
vector<Utilizator> u;
Utilizator user;
while (!f.eof()){
f >> user;
u.push_back(user);
}
f.close();
return u;
}
vector<Raspuns> readAnswers(char* filename){
ifstream f(filename);
vector<Raspuns> u;
Raspuns r;
while (!f.eof()){
f >> r;
u.push_back(r);
}
f.close();
return u;
}
void saveState(vector<Utilizator> u, vector<Raspuns> r){
ofstream f("utilizatori.dat");
ofstream g("raspunsuri.dat");
for (int i = 0; i<u.size(); i++){
cout << u[i] << endl;
f << u[i] << endl;
}
for (int i = 0; i<r.size(); i++){
cout << r[i] << endl;
g << r[i] << endl;
}
f.close();
g.close();
}
Why, precisely, do you not want to use an std::vector for storing an arbitrary number of items in a sequence? The alternative (EDIT: that doesn't use any of the other STL containers) is quite tedious.
What do you want to use instead? std::set? std::deque? It's basically the same way as with a vector.
Or perhaps you're asking how to accumulate statistics without reading entire data sets into memory? It would help to be more clear.
By the way, this is wrong:
1 2 3 4
while (!f.eof()){
f >> user;
u.push_back(user);
}
The read above will fail when it reaches the end of file, and then you'd push an invalid "user" into u without checking.
In general, "while not eof" kind of loop is an error. The correct loop would be: