#include #include #include #include #include #include std::string expand(std::string const& line, std::map const& macros) { std::istringstream iss { line }; std::ostringstream oss { }; std::string word; while (iss >> word) { auto it = macros.find(word); if (it == macros.end()) { oss << word << " "; } else { oss << expand(it->second, macros); } } return oss.str(); } std::map define_macros(std::ifstream& ifs) { std::map macros { }; std::string name; while (std::getline(ifs, name, ':')) { std::string definition; std::getline(ifs, definition); macros[name] = definition; } return macros; } int main() { std::ifstream ifs { "MACROS" }; // auto will become the type of whatever define_macros define // so it is up to you to decide what type type this variable should be. auto macros { define_macros(ifs) }; std::string line; while (std::getline(std::cin, line)) { std::cout << expand(line, macros) << std::endl; } }