Reputation: 79
I have this file u.user that has some data about users in the following format:
835|44|F|executive|11577
836|44|M|artist|10018
This is a text file basically but with the .user extension. I have been trying to use ifstream and getline methods to read one line at a time and store them in some sort of data structure, but it doesn't seem to be working. Error I get:
userbaseGM.cpp:15:18: error: variable âstd::ifstream myfileâ has initializer but incomplete type ifstream myfile ("u.user");
My code is:
int main() {
//template<typename T>
//map<T,T> userMap;
string line;
ifstream myfile ("u.user");
if (myfile.is_open()) {
while ( getline (myfile,line) ) {
cout << line << '\n';
}
myfile.close();
} else cout << "Unable to open file";
}
Any suggestions on what I should be doing instead?
Thank you,
Upvotes: 0
Views: 1371
Reputation: 283634
"incomplete type": Some header file you included provided a forward declaration of the class, but you never included the real definition.
Add
#include <fstream>
near the top of your file, and try again.
Upvotes: 5