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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:56:36+00:00 2026-05-27T08:56:36+00:00

Basically, i want to read highscores from a file and check if the user

  • 0

Basically, i want to read highscores from a file and check if the user has scored enought points to be on the scoreboard. I’m trying to do it like this:

string initials[10];
int scores[10];

//load txt
ifstream highscores("highscores.txt");
if(highscores.is_open())
{
   while(highscores.good())
   {
    for(int x=0;x<10;x++)
    {
        getline(highscores,initials[x],' '); 
        highscores >> scores[x];
    }
   }

    }

the initials are only 3 chars long, so i could implement a 2 dim. array but i wanted to try it with strings. It shows that i mad one string of size 10. How should i write it so it will work with 10 arrays instead of 1? (I know i could make 10 arrays naming them from array1.. to 10, looping through them sound much better. The highscores file is just a set of 10 initialas AAA,BBB etc. and some scores.

Example of highscores.txt:

AAA 5000
BBB 4000
CCC 3000
  • 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-27T08:56:37+00:00Added an answer on May 27, 2026 at 8:56 am

    Use std::map to hold initials and associated score. For example:

    int main()
    {
        // Map is keyed by initials.
        std::map<std::string, int> scores;
    
        std::ifstream in("highscores.txt");
        if (in.is_open())
        {
            for (;;)
            {
                std::string line;
                std::getline(in, line);
    
                if (!in.good())
                {
                    break;
                }
    
                const size_t space_idx = line.find(' ');
                if (std::string::npos != space_idx)
                {
                    // The initials are everthing before the space.
                    // Score everything after the space.
                    scores[line.substr(0, space_idx)] =
                        atoi(line.substr(space_idx + 1).c_str());
                }
            }
            in.close();
        }
    
        // Check who has achieved required score.
        for (std::map<std::string, int>::iterator i = scores.begin();
             i != scores.end();
             i++)
        {
            if (i->second > 3500)
            {
                std::cout << i->first << "\n";
            }
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to read and write to a file then save all the
Basically what I want to do is to read a binary file, and extract
Like ini file, I basically want to have an easy-to-edit configuration file that can
I'm trying to interface with Joysticks in Objective-C, basically I want to read out
I want to read a Open Office Document spreadsheet (.ods file) from my android
Basically I have a file called FlowLayout.html and I want to read it into
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
I basically want to open a browser window from Word using VBA that does
I want to read a log file that is constantly being written to. It
I have a CSV file, I want to read this file and do some

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.