• 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
    ",x);
            }
            else{
                cnt++;
                if(x[0]=='C')
                {
                    printf("%s
    ",bu);
                }
                if(x[0]=='B')
                {
                    printf("%s
    ",jiandao);
                }
                if(x[0]=='J')
                {
                    printf("%s
    ",chuizi);
                }
            }
        //    printf("%s
    ",x);
        }
        return 0;
    }

    这题我一开始,将 bu,chuizi,jiandao数组恰好改成字符数,没有多余1,因为我想着输入输出没有问题,但是输入样例以后,比如:input:ChuiZi,output:BuChuiZiJianDao。。。一口气连在一起的全输出来了。

    ...

    3.<cstdlib>下的abs()函数对整型进行操作,用<cmath>下的fabs()函数对整型进行操作

    error: call of overloaded ‘abs(int)’ is ambiguous

    。。。

  • 相关阅读:
    Spark源码学习1.1——DAGScheduler.scala
    Spark随笔(三):straggler的产生原因
    Spark随笔(二):深入学习
    Spark随笔(一):Spark的综合认识
    Hadoop随笔(二):Hadoop V1到Hadoop V2的主要变化
    Hadoop随笔(一):工作流程的源码
    zookeeper 安装笔记 3.6.7
    OpenStack 与 大数据的融合
    三 概要模式 3) MR计数器计数 。无 reduce 计数
    五 数据组织模式 2) 分区模式 代码
  • 原文地址:https://www.cnblogs.com/greenaway07/p/10536502.html
Copyright © 2020-2023  润新知