我有一个 C++ 程序:
#include <iostream>
using namespace std;
int main (){
char x [10] = "abc";
system (sprintf ("mkdir ", "%s", x)); //error happens here, can't
//convert int to const char*
return 0;
}
结果:
sys.c:8:37: error: invalid conversion from ‘int’ to ‘const char*’
我在哪里将 int 转换为 char?
最佳答案
系统需要一个 const char * 作为输入,而 sprintf 返回一个 int。这是导致您出错的问题。此外,sprintf 的第一个参数必须是一个足够大小的可写缓冲区。
关于c++ - 错误 : invalid conversion from ‘int’ to ‘const char*’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14254215/