C + + Programming Fundamentals 115-enum types

Source: Internet
Author: User

1 //15-enum type. CPP: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7 using namespacestd;8 9 enumHerotype//enum type is integral. Suitable as tag tag. Ten { OneTank,//0 AMagic,//1 -Adc//2 -Assist//3 the }; -  - enumHumantype - { +Teacher =1,//You can modify the values in them -Student =4, +Engineer =5, AFamer =7 at }; - intMain () - { -Herotype herotype = Magic;//defines an enumeration.  -Herotype = ADC;//modifies the value of the enumeration.  -cout << Herotype <<Endl; in  -Humantype Humantype =Famer; to     //Try Two enumerations to be able to work together (' contest ') +Auto MyType = Humantype +Herotype; -cout << myType << Endl;//Yes, I can. the  *     inti = Engineer +3; $cout << i<<Endl;Panax Notoginseng  -Herotype = Herotype (2);//after you cast 2 to a custom enumeration type, you can assign a value to the newly defined herotype.  thecout << Herotype <<Endl; +     //Herotype (2) equals ADC?  Acout <<"Herotype:"<< herotype<<endl<<"ADC:"<< ADC << Endl;//are equal!  the       +     //What if it's 10? Can I assign a value to Herotype?  -Herotype = Herotype (Ten); $cout << herotype << Endl;//Yes, I can. However, it is best not to write this, the assigned number should have the corresponding enumeration type.  $      -     //Teacher = Humantype (4);//If you want to assign a value, you have to initialize it first.  -  the     intT; -CIN >>T;Wuyi     return 0; the}

C + + Programming Fundamentals 115-enum types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.