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