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

 

。。。

原文链接: https://www.cnblogs.com/greenaway07/p/10536502.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++/c遇到的warnings、errors(更新中)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/291553

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午1:44
下一篇 2023年2月15日 下午1:46

相关推荐