从“常量字符*”到“字符*”的转换无效错误

invalid conversion from ‘const char*’ to ‘char*’ error

本文关键字:字符 转换 无效 错误 常量字符 常量      更新时间:2023-10-16

我定义了以下两种类型,

当我在下面的代码片段中使用它们时,我收到此错误:

从"常量字符*"

到"字符*"的转换无效 [-允许] tmp = strstr(tmp, delim);

typedef std::vector<PCCHAR> STR_VEC; /
typedef const char * PCCHAR;
typedef PCCHAR const CPCCHAR;
STR_VEC split(CPCCHAR delim, CPCCHAR buf) 
{
STR_VEC arr;
char *tmp = strdup(buf);
while(1)
{
arr.push_back(tmp);
tmp = strstr(tmp, delim);
if(!tmp)
  break;
*tmp = '';
 tmp += strlen(delim);
}
return arr;
}

如果有人发现同样的错误,下面为我修复了它:

常量字符 tmp1 = (常量字符 *) tmp;tmp1 = (const char) strstr(tmp, delim);