C++ source code to get yaml informations by yaml-cpp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get yaml informations by yaml-cpp. | |
*/ | |
#include "string" | |
#include "yaml-cpp/yaml.h" | |
using namespace std; | |
int main(int argc, char* argv[]){ | |
try{ | |
YAML::Node config = YAML::LoadFile("config.yml"); | |
string hostname = config["db"]["hostname"].as<string>(); | |
string database = config["db"]["database"].as<string>(); | |
string username = config["db"]["username"].as<string>(); | |
string password = config["db"]["password"].as<string>(); | |
cout << "* DB Setting:\n" | |
<< " - HOSTNAME: " << hostname << "\n" | |
<< " - DATABASE: " << database << "\n" | |
<< " - USERNAME: " << username << "\n" | |
<< " - PASSWORD: " << password << endl; | |
} | |
catch(YAML::Exception& e) { | |
cerr << e.what() << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment