Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <map>
- class ConfigFile
- {
- public:
- ConfigFile(const std::string& filename)
- {
- std::ifstream file(filename.c_str());
- std::string line;
- while( std::getline(file, line) )
- {
- std::istringstream iss(line);
- std::string key, value;
- iss >> key;
- iss >> value;
- m_conf.insert( std::pair<std::string, std::string>(key,value) );
- }
- file.close();
- }
- template<typename T>
- const T& operator[](const std::string& key)
- {
- std::ostringstream oss(m_conf[key]);
- T result;
- result << oss;
- return result;
- }
- private:
- std::map<std::string, std::string> m_conf;
- };
- int main()
- {
- ConfigFile cf("config.in");
- double altitude = cf["altitude"];
- std::cout << altitude << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment