check if file is open and ask for password
Hi I am trying to make a program that asks for password when you try to open a file. Any Ideas?
Thanks in advance!
I tried with that, obviously without success :D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main ()
{
ifstream file("test.txt");
string password;
file.close();
while(true)
{
if (file.is_open())
{
file.close();
cout<<"Enter password to use file: ";
cin>>password;
if(password == "hello")
{
cout<<"success\n";
system("start test.txt");
Sleep(10000);
}
if(password != "hello")
{
cout<<"wrong password\n";
file.close();
}
}
}
system("pause");
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.