Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法转换';std::string{aka std::basic_string}';至';常量字符*';对于参数';1';至';整数系统(常量字符*)_C++ - Fatal编程技术网

C++ 无法转换';std::string{aka std::basic_string}';至';常量字符*';对于参数';1';至';整数系统(常量字符*)

C++ 无法转换';std::string{aka std::basic_string}';至';常量字符*';对于参数';1';至';整数系统(常量字符*),c++,C++,我有以下代码作为文件夹锁: #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;

我有以下代码作为文件夹锁:

#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);

  }
}
#包括
#包括
#包括
#包括
#包括
#包括
#定义最大值100
使用名称空间std;
结构文件夹\u全部{
std::字符串名;
std::字符串位置;
};
int main(){
文件夹_所有文件夹[max];
int n;
不能使用以下方法:


如果你只是阅读它,那么这个错误应该是不言自明的。对于一个小问题,这是很多主要无关的代码。你应该真正尝试构建一个MCVE。系统采用
char*
而不是
std::string
。使用
fold.c_str()
char*
传递给
system()
system(fold.c_str());