zoukankan      html  css  js  c++  java
  • C++ 结构体和枚举

    共同体

    共同体(union) 是一种数据格式, 它能够存储不同的数据类型, 但只能同时存储其中的一种类型。也就是说, 结构可以同时存储int、long 和 double, 共同体只能存储int、long、double。

    union one4all {
      int int_val;
      long long_val;
      double double_val;
    }

    没有细研究,暂时先占个位置

    枚举

    int main(int argc, char const *argv[])
    {
        enum {zero, one, two, three};
        std::cout << three << '
    ';
        return 0;
    }


    答案:
    ========================

      root@corleone:/opt/code/testC++/右元/函数# g++ first.cpp -o main
      root@corleone:/opt/code/testC++/右元/函数# ./main
      3

     
    #include <iostream>
    
    
    int main(int argc, char const *argv[]) {
    
      using namespace std;
      enum bits{one=1};
      bits a;
      a = one;
      std::cout << "a:" << a << '
    ';
    
    
      return 0;
    }

    ==================================

    #include <iostream>

    
    

    using namespace std;

    
    

    int main(int argc, char const *argv []){

    
    

    enum name { one = 123 };
    int a = one;
    printf("%d ", a);

    
    

    return 0;

    
    

    }

     
  • 相关阅读:
    洛谷P4547 [THUWC2017]随机二分图
    洛谷P4590 [TJOI2018]游园会
    洛谷P4099 [HEOI2013]SAO
    #4719. 内凸包
    #1612. 天平(scales)
    #3164. 「CEOI2019」立方填词
    #4728. 问题求解
    #2754. Count(count)
    sa模板
    bzoj 2553: [BeiJing2011]禁忌
  • 原文地址:https://www.cnblogs.com/renfanzi/p/7359101.html
Copyright © 2011-2022 走看看