I am not sure exactly how to do this in c++. This is my thought process:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
std::vector<std::string> lines = open("test.txt");
for (auto line:lines){
std::vector<std::string> tokens = split(line);
std::string key = tokens[0];
std::string type = tokens[2];
if (type == "int")
int value = str2int(tokens[1]);
elseif (type == "string")
std::string value = tokens[1];
elseif (type == "double")
double value = str2dou(tokens[1]);
elseif (type == "char")
char value = str2cha(tokens[1]);
}
the conversion from string to (int, double, char) are functions using stringstring to convert to that type. open() splits the file by newline and pushes the line to each element of the vector lines. The file format of each line is KEY VALUE TYPE.