C - [vs2019] C2440 错误,无法从 const char[] 转换为 char*问题解决

https://blog.csdn.net/weixin_45525272/article/details/118699716

原因

新标准中,不能把指针指向一串常量

解决

方案一:引入[]

char*str = “hello world”;

改成:

char str_tmp[] = “hello world”;
char *str = str_tmp;

方案二:加const

char*str = “hello world”;

改成:

const char*str = “hello world”;

方案三:

找到语言的符合模式改为否就可以了。

posted on 2024-11-19 10:35  longyue  阅读(245)  评论(0编辑  收藏  举报

导航