http://faq.cprogramming.com/cgi-bin/...&id=1043284351
Btw, you can use a virtual machine for testing your app at home.
Although the link is for C, the same solution applies to C++ as well (reading using the >> operator).
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
Btw, you can use a virtual machine for testing your app at home.
Although the link is for C, the same solution applies to C++ as well (reading using the >> operator).
Setting up a virtual machine seems complicated, but I'll look into it
Meanwhile, would this work?
Code:void getPass(string userName) { string tempName, password; ifstream userNameDB("users.data"); for (int i = 0; (userNameDB >> tempName); i = i + 2) { userNameDB >> tempName; if (tempName == userName) { i++; userNameDB >> password; userNameDB.close(); logInPASS(userName, password); } } userNameDB.close(); cout << endl << "Error fetching password for " << userName << "." << endl; writeError(1); return -1; }
Well, I imagine it might be on Linux, but on the other hand, it can't be that difficult.
Nope, it will absolutely not work, because you're reading twice.Meanwhile, would this work?
Code:void getPass(string userName) { string tempName, password; ifstream userNameDB("users.data"); for (int i = 0; (userNameDB >> tempName); i = i + 2) { userNameDB >> tempName; if (tempName == userName) { i++; userNameDB >> password; userNameDB.close(); logInPASS(userName, password); } } userNameDB.close(); cout << endl << "Error fetching password for " << userName << "." << endl; writeError(1); return -1; }
userNameDB >> tempName; // Reads user
userNameDB >> tempName; // Reads pass
if (tempName == userName) // Fails
This program should work just fine with your Windows XP machine - there is nothing machine/OS specific in the way your code works, so why not just run it as a Windows console application. That is a 10x simpler solution than virtual machines or such, and as long as you are not depending on OS-specific functionality (that is, you are using standard C/C++ functionality), it shouldn't make any difference.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.