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