I have two questions which relate to this rather simple program:
Question 1. How do I read the first line of a text (which the program creates) into the 'password' variable which is in the below source code?
Question 2. With the code below, I have a problem. This program is meant to read the password which is inputted by the user and then outputted into the text file by the program (still need that bit) and when they try to get back into the program, they need to type in the same password. But no matter what type in, the pogram says that they typed in the wrong password.
Confused? Here's the code:
Code:
#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
int main()
{
char attempt[40];
char password[40];
if(/* text file empty - but how is this checked? */)
{
cout << "You have not set a password. You must set one now:\n";
cin >> password;
ofstream newPass("data.psw");
newPass << password;
}
cout << "Enter your password:\n";
cin >> password;
if(attempt==password) // <-- this password is meant to be read from the text file, but how?
{
cout << "Access granted . . .\n";
// ...program continues...
}
else
{
cout << "Sorry, you have inputted and incorrect password . . .\n";
// ...program exits
}
return 0;
}
Thanks for any help.