It is necessary for the program to compare the version specified in the constant ( const std::string verconst="version=0.2" ) with the version that is stored in the config file. I made reading all the contents from the config, I do not understand how to read a certain part of the text in order to compare it with a constant.
#include <iostream> #include <unistd.h> #include <stdlib.h> #include <fstream> #define _GNU_SOURCE #include <getopt.h> using namespace std; int main(int argc, char *argv[]) { ifstream confFile; const char path[]="~/.config/lesson3/config.ini"; const std::string verconst="version=0.2"; int opt; std::string config, line,ver; bool isConfig = false; static struct option long_options[] = { {"config", required_argument, 0,'c' }, }; int long_index =0; while ((opt = getopt_long(argc, argv, "c:", long_options, &long_index )) !=-1){ switch(opt){ case 'c': isConfig = true; config = optarg; cout << "Config = " << "[ " << config << " ]" << endl; break; } } if(!isConfig){ config = path; cout << "Config = " << "[ " << config << " ]" << endl; } confFile.open(config); if(confFile.is_open()){ while(getline(confFile, line)){ cout << line << endl; } confFile.close(); } else{ cout << "Can't open file: " << config << endl; exit(1); } return 0; }