I have the following code that stimulate as a folder lock:
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<string>
#include<fstream>
#include<process.h>
#define max 100
using namespace std;
struct folder_all{
std::string name;
std::string location;
};
int main(){
folder_all folder[max];
int n;
cout<<"\n\n\t\t\tFolder Locker"<<endl;
if (std::ifstream("data"))
{
cout<<"\n\n\tYour Folders are safe with us"<<endl;
cout<<"Enter your password to unlock(Password will not be visible): ";
HANDLE inHandle = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(inHandle, &mode);
SetConsoleMode(inHandle, mode & ~ENABLE_ECHO_INPUT);
std::string inpass;
cin>>inpass;
SetConsoleMode(inHandle, mode);
}
else{
cout<<"\nNo. of folders to be locked: ";
cin>>n;
HANDLE inHandle = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(inHandle, &mode);
SetConsoleMode(inHandle, mode & ~ENABLE_ECHO_INPUT);
//read the password
std::string password;
cout<<"\nEnter the password(password will not be visible): ";
cin>>password;
/
SetConsoleMode(inHandle, mode);
cout<<"\n\n"<<endl;
for(int i=0; i<n; i++){
cout<<"Enter folder "<<i+1<<" details:"<<endl<<endl;
cout<<"Folder Name: ";
cin>>folder[i].name;
cout<<"Folder Location: "<<endl<<"\tEnter in following format 'Drivelabel://parent-folder/child-folder/folder'"<<endl;
cout<<"\tfor example C://desktop/pics/your-folder"<<endl;
cin>>folder[i].location;
}
std::ofstream o("data");
o <<password<<std::endl;
for(int j=0; j<n; j++){
o<<folder[j].location<<std::endl;
}
system("attrib +h +s +r data");
std::string fold;
for(int k=0; k<n; k++){
std::string f = folder[k].location ;
fold = "attrib +h +s +r " + f + " ";
system(fold); //this line gives me a error
}
cout<<"\nYour folder/s have been locked"<<endl;
cout<<"\nThis application will now exit"<<endl;
exit(0);
}
}
The code asks the user for a password and then it saves it in a file data and hides the file. When user enters the location of the folder to be locked it then also hide it. but it is not working properly for 1 error the error is:
main.cpp|79|error: cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'int system(const char*)'|
How to resolve it?