This gives me a couple of errors when I try to build it,
||=== brugersystem v2, Debug ===|
Line 36 |error: no matching function for call to 'getline(std::string&)'|
Line 59 |error: 'current' is not a class or namespace|
Line 61 |error: 'current' is not a class or namespace|
||=== Build finished: 3 errors, 0 warnings ===|
I am not sure with any of them. The line 59 and 61 errors are given when I want to create a database with a "default" admin member, Line 36 I try to recieve line input from a user. This whole program is to be a sort of vague usersystem. It will check whether the .txt file containing information exists. If not, it should create the database with an default admin account.
||=== brugersystem v2, Debug ===|
Line 36 |error: no matching function for call to 'getline(std::string&)
Well first off you probably want: "getline(cin, pass);"
Line 59 |error: 'current' is not a class or namespace|
Line 61 |error: 'current' is not a class or namespace|
Secondly you're trying to access an object with the wrong operator, try "."
As in "current.users.push_back();"
Without the quotes obviously. Keep in mind you aren't actually pushing anything back either, so, that won't do much. Oh and you should probably use an enum for seclevel.
Bleh, okay, there's actually a lot of things wrong with this whole thing.
EDIT: I "partially" rewrote it for you, I honestly couldn't figure out what you were trying to do on half of it and I couldn't figure out what setPas was supposed to be doing so I just removed it.
Hey, thank you, and sorry for the late answer. Yes, I know, a mess. I did use enums before, but I thought i'd optimize everything when it was all clear and functional. I was thinking, if it is allowed and somewhat accepted to make checks inside the class' constructor even before creating an class object, like this:
Userbase::Userbase()
{
ifstream inFile("userlist.txt");
if (inFile.good())
{
// Read password from first user (admin) in .txt
}
else
rootPass = "Admin1";
inFile.close();
}
Also, I seem not to be able to use push_back() with this,
int main()
{
Userbase userbase;
ifstream inFile;
inFile.open("userlist.txt");
if(inFile.good())
{
// ADD DATE OF MODIFICATION
cout << "USERLIST FOUND, READING USERS.\n";
inFile.close();
}
else
{
cout << "NO USERS FOUND, CREATING NEW LIST.\n";
inFile.close();
userbase.users.push_back(1, "admin", "Admin1", admin);
ofstream outFile("userlist.txt");
time_t current = time(0);
outFile << "created: " << current << "\n";
outFile << "mod_date: " << current << "\n\n";
outFile.close();
}
return 0;
}
It gives me the error at line 78 (Which is the push_back() command),
error: no matching function for call to 'std::vector<userstats, std::allocator<userstats> >::push_back(int, const char [6], const char [7], securityLevel)'|
Btw, all the functions I have written (SetPas(), resetdb()) in the class are ideas that I have written down to remember and fully create when I have sorted this vector thing out. I have not fully written them.
... Whops! Thanks for the heads up. but the problem seem to persist with the same error except for the parameter in the error "int" changing to "const char[3]".
push_back() wants a copy of the object to be put into the container, not the components that make up the object. Give your struct a constructor and pass the relevant information to the constructor in the push_back() call.
Ah, I see. So everytime I want to create a new element in the vector I will have to copy a whole structure object to the vector? I wrote something like this,
Another note: I do not recommend putting using namespace std; on top like that. You are putting all that junk into the global namespace, which isn't good practice. I'd recommend putting it inside functions instead, or at least, only do stuff like this:
using std::cout;
using std::cin;
using std::string;
etc.
Hobbyist game developer, game designer, and gamer.