Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1048129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:24:32+00:00 2026-05-16T16:24:32+00:00

C++ enum question. So I have a list of files, and their IDs that

  • 0

C++ enum question.

So I have a list of files, and their IDs that I need to iterate over, and do stuff to. Most of the stuff is the same, but there are a few file-specific things that need to be done. I tried putting the file IDs in an enum, and iterating over that. Howver, the fileIDs are non contiguous, and jump around.

Currently, I have something akin to this

for(int i = 0; i < FILE_ENUM_MAX; i++)
{
    currentFile = myEnum(i);
    // do stuff
}

enum myEnum {
    file1 = 0x1111,
    file2 = 0x8000,
    file3 = 0x75,
    file4 = 0x120,
    FILE_ENUM_MAX = 4
}

This doesn’t work; I just go through files 0, 1, 2, and 3. I get the idea that I can’t just get the Nth item in an enumeration by asking for item N. So what would be the best way to iterate over this enum? Or should I just get rid of it? I probably could put the items in numerical order, but I’d prefer a solution to where order didn’t matter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:24:33+00:00Added an answer on May 16, 2026 at 4:24 pm

    I guess the low-tech answer might be to skip the enum, and just create a static array:

    #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
    
    int FILE_ENUM[] = { 0x1111, 0x8000, 0x75, 0x120 };
    
    for(int i = 0; i < ARRAYSIZE(FILE_ENUM); i++) {
        currentFile = myEnum[i];
        // do stuff
    }
    

    TJ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a handful of helper methods that convert enum values into a list
I have a question using these same examples - this question is focused on
For my new Pet-Project I have a question for design, that is decided already,
I know that when defining a an enum you can enumerate through the list
The whole story; I have some KeyValuePairs that I need to store in a
I have posted this question a while ago but got a partial answer to
A question that I have never solved. I will illustrate with two code samples
I have an enum that looks as follows: public enum TransactionStatus { Open =
Question. I have an item that can have an individual values or a 'package'
My question is related to Database Design for Revisions? but more complicated. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.