整形前にごめんなさい。それを理解できませんでした...
引数を介して構成ファイルをプログラムに渡しています
特定のパラメータから値を読み取ろうとしています
特定のパラメーターが指定された構成ファイルから文字列を返すための次のメソッドを備えた cofigReader クラスがあります
私の問題、
パラメータが見つかりません。見つかったのは 0 または -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();
}
より詳しい情報。構成ファイルは次のようになります。
toemail=someemailaddress@gmail.com
outputdir=C:\tmp
このように使用される configReader クラス
//attempt to parse out the required parameters for the program
string toemail = config.value(configFileArg,"toemail");
常に空を返します