wwrite专题

常量与指针间的转换 warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

最近重新学习C语言,在指针数组处遇到了点问题: 代码如下: #include <stdio.h>int main(){char *p[3] = {"how r u ?","i'm fine,thanks.","and u ?"};int i;for(i = 0 ; i < 3 ; i ++){printf("%s\n", p[i]);}return 0;} 最后可编译,但是显示警告:w

解决C++中[Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

#include<stdio.h>#include<string.h>int main(){int substring(char* s, char a);char *string= "aaabbbcc"; //warning的原因是字符串常量存放在const内存区...//而字符串指针变量定义却是指向char型,稍微有点区别,但是不影响结果。 char b = 'c';printf("%d