I summaryped CSimpleIniA, in a Config category to management Options in a config.ini file.
In the example I provide, sample_size
is read in the Config
constructor.
When readSampleSize()
is called, the value of the configuration file is returned.
By contrast, readInitialPos()
should (what I expected) be able to read the config.ini
and return the value of inital_pos
. Instead, it returns the default value, the third argument 70000
.
I don t understand why this second method is not working.
config.hpp
class Config {
private:
unsigned long int sample_size;
public:
unsigned long int readInitialPos ();
unsigned long int readSampleSize ();
CSimpleIniA ini;
Config ();
};
config.cpp
#include "../include/config.hpp"
Config::Config ()
{
CSimpleIniA ini;
int error_nr = ini.LoadFile("config/config.ini");
if ( error_nr ) {
cout << "Error " << error_nr << " opening config.ini file." << endl;
exit(3);
}
sample_size = ini.GetLongValue("Rock", "sample_size", 50);
}
unsigned long int Config::readInitialPos ()
{
return ini.GetLongValue("Rock", "initial_pos", 70000);
}
unsigned long int Config::readSampleSize ()
{
return sample_size;
}
电话:岩石。
void Rock::readConfig ()
{
Config config;
initial_pos = config.readInitialPos ();
sample_size = config.readSampleSize ();
}