-1

This is the file that I need to read.

id=1    
Name=test
Path=/var/www

I can read this file like this:

std::ifstream f("/home/atmoner/conf.ini");
std::string s;

But how do I read the var Path with c++?

rjdkolb
  • 10,377
  • 11
  • 69
  • 89
Julien
  • 1,946
  • 3
  • 33
  • 51

1 Answers1

0

Boost option:

std::string path;
boost::program_options::variables_map vm;
boost::program_options::options_description desc(
    "Allowed options");

desc.add_options()
    ("Path", boost::program_options::value<std::string>(&path), "document here...");

// boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::store(boost::program_options::parse_config_file<char>("a.ini", desc), vm);
notify(vm);

//now variable path will contain the value.

Fplus option

string line = "Path=/var/www";
std::vector<std::string> vs = fplus::split('=', false, line);
string key = vs[0];
string value = vs[1];

Hand written:

std::string s="Path=/var/www";
string::iterator it = std::find(s.begin(), s.end(), '=');
if(it!=s.end())
{
    std::string key(s.begin(), it);
    std::string value(it+1, s.end());
}
scinart
  • 457
  • 2
  • 9