Then a little (or a lot) more information about the structure of the program would help.
Then a little (or a lot) more information about the structure of the program would help.
Code:system("cd desktop"); system("cls"); ifstream verpass ( "password.txt" ); if ( string pass; cout << "Please Enter Your Passsword: "; cin >> pass; ofstream passfile ( "password.txt" ); passfile << pass << endl; passfile.close(); system("cls"); string pass2; cout << "Please enter it again: "; cin >> pass2; if ( pass != pass2 ) { system("cls"); cout << "Password verification is incorrect!" << endl; system("pause"); } else { system("cls"); cout << "Password verification is correct!" << endl; system("pause");
If you're going to use system() so much, you may as well write a batch file!.
> system("cd desktop");
Is the most useless thing in the universe?
Why?
Your program is in directory foo
You do system("cd desktop");
A new process is created, and a cmd.exe is run
The cd command is run in that new process (so it is now in foo/desktop)
The new process exits.
Your code is still in directory foo.
1. Why are you opening the same file twice?Code:ifstream verpass ( "password.txt" ); if ( string pass; cout << "Please Enter Your Passsword: "; cin >> pass; ofstream passfile ( "password.txt" );
2. What is that bare if ( doing?
My advice is you start with a lot more reading, and then try "hello world" again, because it seems like you're just stumbling around in the dark hoping to find something useful.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok ok... wait -- what im really asking is this --> how would i be able to verify that a text file is present or if it does not exist?
The most portable (and maybe only portable) way to verify that a file exists is to open it for read. If the open fails, then the file does not exist.
oh duh! that makes sense! thanks!
but one last problem --> what method would i use to verify whats in the textfile? I know you have to do a ifstream to the file but im having the problem of how i would compare the two strings.
and tthis is where i go blankCode:string passwordmade; cout << "Please Enter Your Password: "; cin >> passwordmade; ifstream passwordconfirm ( "passwordverify.txt" ); if ( passwordmade ==
(this is after the text file is confirmed and the program asks to verify the contents of the text file.)
Last edited by Warhawk; 09-27-2005 at 08:28 PM.
do i have to declare a string that equals a string in the text file? kinda like in fstream when you use this:
Code:ifstream passwrd ("password.txt"); cout << str; passwrd.close();
You could try something like this.
Code://declare string to hold file name string filename; //obtain file name cout << "enter file name/path" << endl; cin >> filename; //declare ifstream to read from file ifstream filein(filename.c_str()); //see if file opened or not if(!filein) { //file didn't open cout << "unable to open " << filename << endl; //file called file name may not exit or you have //incorrect path to file or whatever } else { //file did open //declare string to hold password from file string password = "empty"; //read file data into password filename >> password; if(password == "empty") { //file called filename existed but was empty cout << "no password in " << filename << endl; } else { //declare string for user input string input; //ask user for input cout << "enter password" << endl; cin >> input; //compare user input to password from file if(password == input) { cout << "proceed" << endl; } else { cout << "try again" << endl; } } }
Last edited by elad; 09-29-2005 at 09:06 AM.
You're only born perfect.