我试图发送一个运行特定python脚本的命令:但是,每当程序到达执行行时,就会发生这种情况:
中的0x69bd1f16处出现未处理的异常游戏服务器.exe:0xC0000005:访问冲突读取位置0x46f520ca
程序停止共振并崩溃。以下是所讨论的方法:
void ScriptManager::runScript(std::string scriptName, std::string args[])
{
std::string py = "python " + scriptName;
std::cout << py << std::endl;
for(int i = 0; i < args->length(); i++)
{
py += " " + args[i];
std::cout << py << std::endl;
}
std::cout << py << std::endl;
std::system(py.c_str());
}
这将调用上述函数:
void DBFactory::dbRegisterUser(std::string username, std::string password)
{
ScriptManager script;
std::string data[] = {username, password};
script.runScript("Python.py", data);
}
据我所知,脚本没有运行。如果有帮助的话,我也可以发布脚本。你知道吗
这就是问题所在:
args->length()
等价于args[0].length()
;也就是说,您将数组中第一个字符串的长度作为索引。经过两次迭代之后,您将访问数组的末尾。最佳解决方案是(所有示例均未经测试):使用^{} (C++ 11):< /p>
使用^{} (示例使用C++ 03):
将数组大小作为参数传递:
我个人更喜欢例1,也会像避免瘟疫一样避免例3。示例2运行良好,但可能没有示例1快。你知道吗
相关问题 更多 >
编程相关推荐