I'm writing a program that needs to read input both from a file and from user input. For example, I will need the input from a user for example a password, and then check if the password is correct by comparing it with a password from a file. After that, I want to ask for more user input again and so on. I wonder if there is any way to do this? Thanks in advance.
Edit: Thanks for the comments to let me know that I should put in some code. This is my first time here so I'm sorry for the inconvenience.
#include <iostream>
#include <cstdio>
using namespace std;
string pass;
string userpass;
void getPassword()
{
ios_base::sync_with_stdio(0);
freopen("PASS.TXT", "r", stdin);
cin >> pass;
}
int main()
{
cout << "Please enter your password: ";
cin >> userpass;
getPassword();
if (userpass == pass)
{
char yes;
cout << "Correct password!\nType \"Y\" to continue... ";
/*
cin >> yes;
if (yes == 'Y')
{
cout << "Do something here";
}
*/
// Now I need to get user to type "Y"
// but if I use cin then it will continue
// to get input from the file
}
else
{
cout <<"\nWrong password...";
}
return 0;
}