c++/c遇到的warnings、errors(更新中)
1.PTA做题之warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
百度之
https://www.e-learn.cn/content/wangluowenzhang/88661
我觉得比较简单的方法是:
(void)scanf("%d",&t);
好吧,简单但是并没有用。。。
a.cpp: In function ‘int main()’:
a.cpp:24:28: error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator!=’
while((void)scanf("%d",&n)!=EOF)declared with attribute warn_unused_result [-Wunused-result]
原来只是
a.cpp:29:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%llu%d%d",&s[i].a,&s[i].b,&s[i].c);
...
2.PTA做水题。<稳赢>AC代码
#include <iostream> #include <algorithm> #include <cmath> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <cstring> #include <string> using namespace std; char chuizi[7]={'C','h','u','i','Z','i'}; char bu[3]={'B','u'}; char jiandao[9]={'J','i','a','n','D','a','o'}; int main() { int n; scanf("%d",&n); getchar(); char x[9]; int cnt; while(1) { scanf("%s",x); getchar(); if(x[0]=='E') break; if(cnt==n) { cnt=0; printf("%s\n",x); } else{ cnt++; if(x[0]=='C') { printf("%s\n",bu); } if(x[0]=='B') { printf("%s\n",jiandao); } if(x[0]=='J') { printf("%s\n",chuizi); } } // printf("%s\n",x); } return 0; }
这题我一开始,将 bu,chuizi,jiandao数组恰好改成字符数,没有多余1,因为我想着输入输出没有问题,但是输入样例以后,比如:input:ChuiZi,output:BuChuiZiJianDao。。。一口气连在一起的全输出来了。
...
3.<cstdlib>
下的abs()函数对整型进行操作,用<cmath>
下的fabs()函数对整型进行操作
error: call of overloaded ‘abs(int)’ is ambiguous
。。。