小编rus*_*jen的帖子

在c ++中使用枚举作为数组索引

#include <stdlib.h>
#include <stdio.h>
using namespace std;



void main(){
    char *resolutions[] = { "720x480", "1024x600", "1280x720", "1920x1080" };

    int x = 0;

    enum ResMode
    {
        p480,
        p600,
        p720,
        p1080
    }; 
    ResMode res = p480;

    printf("\nPlease enter the resolution you wish to use now by entering a number");
    printf("\n480p[0], 600p[1], 720p[2], 1080p[3]");
    gets(res);

    printf("\nThe resolution you have selected is %s", resolutions[res]);

}
Run Code Online (Sandbox Code Playgroud)

所以基本上我想能够按1并让它从枚举中选择p600并将其作为1024x600放在下一行.我收到类型转换错误.我怎样才能解决这个问题?

c++ enums

3
推荐指数
1
解决办法
673
查看次数

标签 统计

c++ ×1

enums ×1