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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:57:17+00:00 2026-06-16T02:57:17+00:00

sorry in advance for the formatting. Couldn’t figure it out… I’m passing a config

  • 0

sorry in advance for the formatting. Couldn’t figure it out…

I’m passing a config file to a program via arguments

I’m trying to read a value from a specific parameter

I’ve got a cofigReader class with the following method for returning a string from a config file given a specific parameter

My problem,

it never finds the parameter. found is either 0 or -1….

string configReader::value(string config_file, string parameter)
{
    string value;
    char config_delimiter = '=';
    size_t found;
    file.open(config_file);
    std::string line;
    bool param_found = false;
    while(param_found == false){
        while (!file.eof())
        {       
            getline(file,line);
            logger.writetolog("INFO","Looking for " + parameter +
                         " on line "+ line); 
            found = line.find(parameter);
            logger.writetolog("INFO",int(found));
            if(found!=string::npos){
                param_found = true;
            }
        }
        param_found = true;
    }
    if (found!=string::npos)
    {   
        size_t a = line.find(config_delimiter)+1;
        logger.writetolog("INFO","Found" + parameter + 
                   "splitting string at delimter" + config_delimiter + 
                   " and return right side value");     
        value = line.substr(a);
        return value;
    }
    else
    {
        return value;
    }
    file.close();
}

more info. Config file reads like this.

toemail=someemailaddress@gmail.com
outputdir=C:\tmp

configReader class used like this

//attempt to parse out the required parameters for the program
string toemail = config.value(configFileArg,"toemail"); 

it ALWAYS return empty

  • 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-16T02:57:18+00:00Added an answer on June 16, 2026 at 2:57 am

    Your while (!file.eof()) loop continues after you find a match, over-writing the value of found which you check later.

    You could fix this by changing your loop to something like

    bool param_found = false;
    while (!param_found && !file.eof()) {       
        if (getline(file,line)) {
            break;
        }
        logger.writetolog("INFO","Looking for " + parameter +" on line "+ line); 
        found = line.find(parameter);
        logger.writetolog("INFO",int(found));
        if(found!=string::npos){
            param_found = true;
            break;
        }
    }
    

    instead. (Notice that this code removes your while(param_found == false) loop. As sftrabbit points out, that loop is unnecessary.)

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

Sidebar

Related Questions

All, Sorry in advance for the ambiguous title. Here's what I'm trying to do...
Sorry in advance that this might be a little challenging to read... I'm trying
Sorry in advance for this being such a beginner question. Here are the steps
Sorry in advance everyone for this question as I know the cascading select boxes
sorry in advance for any orthographic mistakes (english is not my first language). I
In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and
I am new to JPA and JBoss, so sorry in advance if this is
Sorry for the long explanation. Thanks in advance to all who are taking their
Sorry if this is too simple, but thanks in advance for helping. This is
Sorry for question but I can't find answer anywhere on internet. I couldn't find

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.