编程题中所遇到的编译错误
编译错误 1:
error: variably modified 'stack1' at file scope
出现错误代码段:
const int MaxSize 50; int id[MaxSize];
修改方法:
#define MaxSize 50 int id[MaxSize];
编译错误 2:
warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wun
出现错误代码段:
int m, n; //第一种 scanf("%d", &m); //第二种 for(int i = 0; i < n; i++) { scanf("%d", &m); }
修改方法:
int m, n; //第一种 if (scanf("%d", &m)) { /* code */ } //第二种 for(int i = 0; i < n; i++) { if (scanf("%d", &m)) { /* code */ } }
编译错误3:
ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
出现错误代码段:
char *s = "wqwz";
修改方法:
//使用类型强转 char *a = (char *)"wqwz"; //将字符串常量赋给字符指针常量 const char *a = "wqwz";
未完待续。。。