Reading files using some Pyhton or any script and converting data into C++ key=>value pair (STL maps)
It is not quite clear what you are actually trying to do. However, if you merely want to read the contents of the file into a std::map
at runtime, then you just have to parse the lines of the file:
#include <iostream>
#include <string>
#include <sstream>
#include <map>
int main() {
//
std::stringstream ss{R"(#define David data(12345)
#define Mark data(13441)
#define Sarah data(98383)
#define Coner data(73834))"};
std::map<std::string, std::string> m;
std::string line;
while (std::getline(ss,line)){
std::string dummy;
std::string name;
std::string data;
std::stringstream linestream{line};
linestream >> dummy >> name >> data;
auto start = data.find('(');
auto stop = data.find(')');
m[data.substr(start+1,stop-start-1)] = name;
}
for (const auto& e : m) {
std::cout << e.first << " " << e.second << "\n";
}
return 0;
}
You merely have to replace the stringstream with an ifstream
.