Created
September 27, 2014 04:08
-
-
Save komasaru/6972caa0f09cd39f1b1a to your computer and use it in GitHub Desktop.
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