Hi , gr8 progress wow. yeah i agree the best way to work with text files would involve loading them to a container in RAM escpecially when they are quite large to avoid the overhead that would be incurred by calling streams multiple times when we need to use the txt file data.
The reason I used a map is because they offer a fast look up as compared to most library containers, we can use the username as the index whle the password is the value at the index, for vectors they are awesome but when it comes to lookup you might end up using O(n) as compared to O(1) lookup time that a map could offer, however vectors can still be fine for small numbers of records.
Another pointer I could suggest to improve your program efficiency, avoid using multiple textfiles - in your case I can see that each user added to your system will secure him\herself a textfiles in your DIR, well am sure that a single textfile will perform better, by this I mean the addUser function will always new users to a single file as opposed to (n) textfiles laying around.
For password string parse to lookup for the characters after it well here is a workable solution
1 2 3 4 5 6 7
|
std::string line, passwrd;
getline (myfile, line);///acquire the string from file.
///search for the phrase "password"
auto index=line.find ("Password:"); ///index holds the first index at which password occurs
index+=9;///9 is the length of "password:", now index is located after the password sub- string.
passwrd=line.substr(index,(line.size ()-index));///passwrd contains your password.
|
However if we use a single textfile to hold our users records we can alter slightly how data is stored in it such that we can completely do away with the overhead induced by parsing strings.
Also I din't quite clearly get what this intended to mean
I'm basically in the process of rewriting it to support the .txt files |