.ini file reading

1

Is it possible to do variable readings in arquivos.ini with C ++?

Ex:

host = "localhost"
name = "username"
pass = "password"
port = 1010

When reading from this file I set it to ifstream .

ifstream dados;
dados.open("arquivo.ini); 
while(getline(dados, linha)){
void sethost(linha){
this->host = linha;
}
}

Given that I want only the value of each ex: host variable I want localhost .

    
asked by anonymous 31.08.2015 / 22:58

1 answer

2

Use a ready library or you will make a lot of mistakes.

CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile("arquivos.ini");
const char * pVal = ini.GetValue("config", "host", NULL);
ini.SetValue("config", "host", "127.0.0.1");
    
31.08.2015 / 23:47