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 7083543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:11:28+00:00 2026-05-28T07:11:28+00:00

Suppose I am working on a card game, and I am using the numbers

  • 0

Suppose I am working on a card game, and I am using the numbers 0 to 3 to represent the suits internally, as it’s easier to work with numbers. So:

0 is equivalent to hearts
1 is equivalent to clubs
2 is equivalent to spades
3 is equivalent to diamonds

When I need to output the suits as strings, though, I can easily use an array of strings to convert them, like this one:

char *suits[] = {"heats","clubs","spades","diamonds"};

So that I can type:

cout << suits[card.suit] 

and the output would be the exact string of the suit.

What if I want to do this the other way around though? That is, I’ll be reading the suits from a file as strings, and I want to convert them to their respective numerical value (0 to 3) on the fly. How can I do it?

My initial idea was to create a very small hash table (i.e., 4 elements in this case), then hash the strings as I read them and get their respective numerical value from the hash table.

Is there an easier way I am missing (specifically in C or C++)?

  • 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-28T07:11:29+00:00Added an answer on May 28, 2026 at 7:11 am
    std::map<std::string, int> assoc;
    assoc["hears"] = 0;
    assoc["clubs"] = 1;
    ...
    
    char *suits[] = {"heats","clubs","spades","diamonds"};
    
    for (char *data : suits)
    {
       std::cout << assoc[data];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a card game engine in C# .NET for some time
I'm working on a game and I'm struggling to get some generic functionality. Suppose
Suppose I have this simple app working : # model class Project has_many :numbers
Suppose you're working on a project and the time/money budget does not allow 100%
Suppose I'm working on a MongoMapper class that looks like this: class Animal include
I suppose this question is more general than working with COM components. I have
hi i am working on a shellscript.. suppose this is the data my shell
now I am working with python. So one question about dict .... suppose I
Suppose you are working on an API, and you want nice URLs. For example,
Suppose that my working copy ~/WC/ is up to date with http://acme.com/svn-rep/ A /.

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.