Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created September 27, 2014 04:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save komasaru/6972caa0f09cd39f1b1a to your computer and use it in GitHub Desktop.
C++ source code to get yaml informations by yaml-cpp.
/**
* 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