“const char *“ 类型的值不能用于初始化 “char“ 类型的实体

因为const char* 和char *类型不匹配

解决的方法有三种:

  • 使用强制类型转换:
char str = "hello world";   //错误代码  双引号

char str = (char)"hello world";//正确代码  使用强制类型转换
  • 先用字符数组进行存储,再使用指针:
char str[] = "hello world";
  • 在项目上右键,选择“属性”,选择“C/C++”,然后在“语言”中,把“符合模式”改为“否”。

猜你喜欢

转载自blog.csdn.net/AII_IIA/article/details/113781419