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

  • Home
  • SEARCH
  • 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 3392614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:56:44+00:00 2026-05-18T03:56:44+00:00

I have the following code snippet which is working fine: ifstream NDSConfig( NDS.config )

  • 0

I have the following code snippet which is working fine:

 ifstream NDSConfig( "NDS.config" ) ;
        string szConfigVal ;
        while( getline( NDSConfig, szConfigVal ) )
        {
            //code
        }

But the problem is I need to update a check box state by comparing the line values. The code then will similar to the following:

 ifstream NDSConfig( "NDS.config" ) ;
        string szConfigVal ;
        while( getline( NDSConfig, szConfigVal ) )
        {
            if(szConfigVal == "AutoStart = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "AutoStart = 0")
            {
                      //Set Check Box False
            }

            if(szConfigVal == "AutLogHistory = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "AutLogHistory = 0")
            {
                      //Set Check Box False
            }

            if(szConfigVal == "AutoScan = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "AutoScan = 0")
            {
                      //Set Check Box False
            }

            if(szConfigVal == "AutoMount = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "AutoMount = 0")
            {
                      //Set Check Box False
            }

            if(szConfigVal == "AutoOpen = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "AutoOpen = 0")
            {
                      //Set Check Box False
            }

            if(szConfigVal == "LastConnectedSvr = 1")
            {
                      //Set Check Box True
            }
            else if(szConfigVal == "LastConnectedSvr = 0")
            {
                      //Set Check Box False
            }
        }

If I am going to use while loop then my state will be over riden and only last in the loop value or state will be updated. Is there any other way out. I need to set the check box values after reading from config file . The Config file looks as below:

AutoStart = 0
AutLogHistory = 1
AutoScan = 1
AutoMount = 0
AutoOpen = 0
LastConnectedSvr = 1

Though I can have only single if and everything else as else if will help but I need a better way.

  • 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-18T03:56:45+00:00Added an answer on May 18, 2026 at 3:56 am

    Alternatively, use boost::program_options, this is designed perfectly for what you require!

    EDIT: little more detail, program_options has a method to parse a config file, such as yours, and as you configure program_options, you can pass in the variable to store the value from the config file in. Have a look at their simple example, it will become abundantly clear…

    Other option is for you to store your keys in a map, with a default value of 0, and then as you parse through your file, set the key to the value you read from the file…

    EDIT:

    using program options (this is untested code, please try refer to the documentation and fix as needed!)

    int AutoStart;
    int AutLogHistory;
    int AutoScan;
    int AutoMount;
    int AutoOpen;
    int LastConnectedSvr;
    
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help", "produce help message")
        ("AutoStart", po::value<int>(&AutoStart)->default_value(0),"AutoStart")
        ("AutLogHistory", po::value<int>(&AutLogHistory)->default_value(0),"AutLogHistory")
        ("AutoScan", po::value<int>(&AutoScan)->default_value(0),"AutoScan")
        ("AutoMount", po::value<int>(&AutoMount)->default_value(0),"AutoMount")
        ("AutoOpen", po::value<int>(&AutoOpen)->default_value(0),"AutoOpen")
        ("LastConnectedSvr", po::value<int>(&LastConnectedSvr)->default_value(0),"LastConnectedSvr")
    ;
    
    std::ifstream config("NDS.config");
    
    po::parse_command_line(config, desc, true);
    

    When that lot runs, the various integers will have the values from the file (or be defaulted to 0).

    The neat thing with this approach is that you can have different types in your config files, and as long as they are formatted as INI files, then this will work.

    The other approach using std::map, well @Moo-Juice has already added working code…

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

Sidebar

Related Questions

I have the following code snippet which uses'event' My fellow developers argue that the
I have the following snippet of code of which I do not have access
I have the following php code, which has been snipped for brevity. I am
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I have the following snippet of code, changeTextArea is a TextArea object. changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
I have the following snippet of code that's generating the Use new keyword if
I have the following snippet where I would like to extract code between the

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.