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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:41+00:00 2026-06-13T23:18:41+00:00

I have a text file named settings.txt . Inside it i have it saying:

  • 0

I have a text file named settings.txt. Inside it i have it saying:

Name = Dave

I then open the file and loop the lines and characters in my script:


    std::ifstream file("Settings.txt");
    std::string line;

    while(std::getline(file, line))
{
    for(int i = 0; i < line.length(); i++){
        char ch = line[i];

        if(!isspace(ch)){ //skip white space

        }

    }
}

What I am trying to work out is assign each value to some kind of variable which will count as my “global settings” for the game.

So the end result would be something like :

Username = Dave;

But in such a way i can add extra settings at a later date. I can’t work out how you would do it =/

  • 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-06-13T23:18:42+00:00Added an answer on June 13, 2026 at 11:18 pm

    To add extra setting, you have to reload the setting file. By keeping setting in a std::map, new settings can be added, or override existing setting. here is an example:

    #include <string>
    #include <fstream>
    #include <iostream>
    
    #include <algorithm>
    #include <functional>
    #include <cctype>
    #include <locale>
    
    #include <map>
    
    using namespace std;
    
    /* -- from Evan Teran on SO: http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring -- */
    // trim from start
    static inline std::string &ltrim(std::string &s) {
            s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
            return s;
    }
    
    // trim from end
    static inline std::string &rtrim(std::string &s) {
            s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
            return s;
    }
    
    // trim from both ends
    static inline std::string &trim(std::string &s) {
            return ltrim(rtrim(s));
    }
    
    int main()
    {
        ifstream file("settings.txt");
        string line;
    
        std::map<string, string> config;
        while(std::getline(file, line))
        {
            int pos = line.find('=');
            if(pos != string::npos)
            {
                string key = line.substr(0, pos);
                string value = line.substr(pos + 1);
                config[trim(key)] = trim(value);
            }
        }
    
       for(map<string, string>::iterator it = config.begin(); it != config.end(); it++)
       {
            cout << it->first << " : " << it->second << endl;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file named num.txt who's only contents is the line 123
I have a text file which contains something like this: Hello, my name is
I have this xml file which has text init. i.e Hi my name is
I have an .erb file where I'd like to return the following text: Name
I'm using ruby's File to open and read in a text file inside of
I have a text file that contains a list of filenames, minus the extension,
I have text file with some stuff that i would like to put into
I have text file with something like first line line nr 2 line three
I have Text file that contains data separated with a comma , . How
I have written a program in Java to read in a text file of

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.