If I understood it correctly, you must create a system "dogwatch" (If I'm right about your case, the Windows Handle API for files).
BTW, I have already thought in implementing that... Sometimes you just really don't need it.
Good luck!
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string fileName;
std::string filePassword;
std::cout << "Please enter the name of the file you'd like to open: ";
std::cin >> fileName;
std::ifstream myFile(fileName);
if(!myFile.is_open())
{
std::cout << "File does not exist" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Please enter the password to read this file: ";
std::cin >> filePassword;
if(filePassword == "hello")
{
while(!myFile.eof())
{
std::cout << char(myFile.get());
}
}
else
{
std::cout << "Incorrect Password" << std::endl;
}
myFile.close();
return 0;
}
This small program first asks for the file in which to open. If the file doesn't exist, it tells you so, and exits (It looks, by default, in the directory the program is being run from). If the file does exist, the program continues to ask for a password, if the password typed by the user is "hello", I output the file to the user by iterating through the file character by character (checking that the current character isn't the EOF [End of File] and output that character). Otherwise, I tell them the password is incorrect. I finish by closing the file. Make sense?
@OP Explain it better, please. What do you want? The users input a file to be open and asks for a password (INSIDE THE PROGRAM)? Or do you want that, in desktop, when user tries to open the file, a pop-up appears and asks for a password?
if i want that in desktop, when user tries to open the file, a pop-up appears and asks for a password? then what the code is likely to be? can you explain? and another thing if there is some way can it be applied on folders also? If yes please mention the code.