C语言枚举类型

来源:百度知道 编辑:UC知道 时间:2024/05/01 21:24:52
谭浩强在C二版中说的枚举类型,例11.13中,
enum color{red,ye,blue,wh,black};
enum color i,j;
……
for(i=red;i<=black;i++)
……
编译系统出错,应该是在自加那一步错误了!高手指点一下应该怎么实现自加那一步的功能,前提是用枚举类型。(系统提示enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator)我用的是VC++环境

把文件名改为.c
用C来编译就行了.

可以改为for(i=red;i<=black;((int)i)++)

原文我没看过。下面的测试在dev-C++ 通过。
#include<stdio.h>
#include <iostream>

enum color{red,ye,blue,wh,black};

enum color i,j;

int main()
{
for(i=red;i<=black;((int)i)++)
std::cout << i << std::endl;
system("pause");
return 0;
}
输出 0 1 2 3 4