佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 923|回复: 9

C++:怎样用enum???

[复制链接]
发表于 5-3-2006 08:07 PM | 显示全部楼层 |阅读模式
#include<iostream>
using namespace std;

enum color{red,green,coklat,orange,blue,white};


int main(){
        for (int s=red;<=white;s++){
        cout<<s;
        return 0;}}

什么问题??
回复

使用道具 举报


ADVERTISEMENT

发表于 6-3-2006 02:28 AM | 显示全部楼层
#include "stdafx.h"
#include<iostream>
using namespace std;

enum color{red,green,coklat,orange,blue,white};


int main(){
        for (int s=red;s<=white;s++)
                cout<<s;
        return 0;
}
不知道是不是你要的答案。
回复

使用道具 举报

 楼主| 发表于 6-3-2006 09:57 PM | 显示全部楼层
原帖由 vampcheah 于 6-3-2006 02:28 AM 发表
#include "stdafx.h"
#include<iostream>
using namespace std;

enum color{red,green,coklat,orange,blue,white};


int main(){
        for (int s=red;s<=white;s++)
                cout< ...

有问题的!!
回复

使用道具 举报

 楼主| 发表于 6-3-2006 10:21 PM | 显示全部楼层
怎样弄identity MATRIX ??
想到半命,做了还是失败!!
回复

使用道具 举报

发表于 6-3-2006 11:52 PM | 显示全部楼层
原帖由 暗之天使 于 6-3-2006 09:57 PM 发表

有问题的!!

你用什么compiler ?我的是microsoft visual C++ express edition,可以run阿。
result -->  012345

[ 本帖最后由 vampcheah 于 6-3-2006 11:53 PM 编辑 ]
回复

使用道具 举报

发表于 7-3-2006 01:55 AM | 显示全部楼层
原帖由 暗之天使 于 6-3-2006 09:57 PM 发表

有问题的!!


不是把?你真的照抄?
#include<iostream>
using namespace std;

enum color{red,green,coklat,orange,blue,white};


int main()
{
        for (int s=red;s<=white;s++)
                cout<<s;
        return 0;
}
这样就对了,#include "stdafx.h"是不用include 的...
还有注意看你的for loop,少了一个s, for(int s=red;<=white;s++)
加多一个s,for(int s=red;s<=white;s++)
下次不要那么粗心了..

[ 本帖最后由 evo9 于 7-3-2006 02:03 AM 编辑 ]
回复

使用道具 举报

Follow Us
发表于 7-3-2006 02:04 PM | 显示全部楼层
原帖由 evo9 于 7-3-2006 01:55 AM 发表


不是把?你真的照抄?
#include<iostream>
using namespace std;

enum color{red,green,coklat,orange,blue,white};


int main()
{
        for (int s=red;s<=white;s++)
             ...

奇怪,我的compiler 不能没有#include "stdafx.h" 。

[ 本帖最后由 vampcheah 于 7-3-2006 02:05 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 7-3-2006 09:44 PM | 显示全部楼层
原帖由 vampcheah 于 6-3-2006 11:52 PM 发表

你用什么compiler ?我的是microsoft visual C++ express edition,可以run阿。
result -->  012345

我要PRINT出COLOR!!




#include "stdafx.h"
这个用不到
回复

使用道具 举报


ADVERTISEMENT

发表于 7-3-2006 10:47 PM | 显示全部楼层
原帖由 暗之天使 于 7-3-2006 09:44 PM 发表

我要PRINT出COLOR!!




#include "stdafx.h"
这个用不到

用array 或vector就可以了。何必用enum ?
回复

使用道具 举报

发表于 7-3-2006 10:52 PM | 显示全部楼层
如果我没有错的话,enum是做不到这样的...
有错请纠正....
这样做就可以了...
#include<iostream>
#include<string>

using namespace std;

const string color[6]={"red","green","coklat","orange","blue","white"};

const int maxcolor=6;
int main()
{
                int i;
                for(i=0;i<=maxcolor;i++)
                        cout<<color[i]<<endl;
                return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 22-9-2024 01:40 AM , Processed in 0.111322 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表