这段代码给了我运行时异常:Unhandled exception at 0x00401189 in ControlFileChanges.exe: 0xC0000005: Access violation writing location 0xbaadf00d在第一个strcpy命令.
char** withStrings(string s1, string s2, string s3, string s4, string s5)
{
char** pipes;
pipes = (char**) malloc(sizeof(*pipes)*5);
strcpy(pipes[0],s1.c_str());
strcpy(pipes[1],s2.c_str());
strcpy(pipes[2],s3.c_str());
strcpy(pipes[3],s4.c_str());
strcpy(pipes[4],s5.c_str());
return pipes;
}
Run Code Online (Sandbox Code Playgroud)
知道问题可能是什么?(这是我在实际代码中使用类似逻辑的示例).
你没有分配内存pipes[0],pipes[1]等等.
既然这是C++而不是C,你考虑使用new而不是malloc?或者也许使用a vector或strings?
| 归档时间: |
|
| 查看次数: |
314 次 |
| 最近记录: |