Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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++ osx授权服务错误_C++_Macos - Fatal编程技术网

C++ osx授权服务错误

C++ osx授权服务错误,c++,macos,C++,Macos,因此,我试图制作一个需要root权限的应用程序,我发现了这个函数,但我不断得到一个错误,“没有匹配的成员函数用于调用‘push_back’”,我尝试将向量更改为string,然后将其转换为char*但后来我得到了分段错误11 static bool execute(常量字符串和程序、常量向量和参数){ 授权参考; if(AuthorizationCreate(NULL,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,&ref)!

因此,我试图制作一个需要root权限的应用程序,我发现了这个函数,但我不断得到一个错误,“没有匹配的成员函数用于调用‘push_back’”,我尝试将向量更改为string,然后将其转换为char*但后来我得到了分段错误11

static bool execute(常量字符串和程序、常量向量和参数){
授权参考;
if(AuthorizationCreate(NULL,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,&ref)!=errAuthorizationSuccess){
返回false;
}
授权项目={
kAuthorizationRightExecute,0,0,0
};
授权权限={1,&item};
const AuthorizationFlags flags=kauthorizationflagsdefaults
|kAuthorizationFlagInteractionAllowed
|KauthorizationFlag预授权
|Kauthorization鞭毛延伸灯;
if(授权版权(参考和权利、KAAuthorizationEmptyEnvironment、flags,0)!=errAuthorizationSuccess){
授权自由(参考,授权权);
返回false;
}
向量args;
for(vector::const_iterator it=arguments.begin();it!=arguments.end();++it){
args.push_back(it->c_str());//此处错误,“没有匹配的成员函数用于调用“push_back”
}
参数推回(0);
OSStatus status=AuthorizationExecuteWithPrivileges(ref,program.c_str(),kAuthorizationFlagDefaults,&args[0],0);
授权自由(参考,授权权);
返回状态==errAuthorizationSuccess;
}

尝试将向量args更改为
向量args
。函数
c_str()
返回一个
const char*
@AndrewB。这不适用于AuthorizationExecuteWithPrivileges接受字符*而不是常量字符*,无论如何,谢谢。如果有什么可以解决错误的话,请尝试
const\u cast(it->c\u str())
。您可能已经知道这一点很久了。@AndrewB。行了,干杯