I need someone to explain to me this code step by step:
/* File config.txt:
num = 123
str = hello
flt = 12.2
*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
struct Config
{
int num;
string str;
double flt;
string myadd;
};
void loadConfig(Config& config)
{
ifstream fin("config.txt");
string line;
while (getline(fin, line))
{
istringstream sin(line.substr(line.find("=") + 1));
if (line.find("num") != -1)
sin >> config.num;
if (line.find("str") != -1)
sin >> config.str;
if (line.find("flt") != -1)
sin >> config.flt;
if (line.find("myadd") != -1)
sin >> config.myadd;
}
}
int main() {
Config config;
loadConfig(config);
cout << config.num << '\n';
cout << config.str << '\n';
cout << config.flt << '\n';
cout << config.myadd;
cin.get();
}
Also I would like it if you gave me a series of suggestions on inprovement, alternateves and an explanation of "regex" the code was by: nucleon