{"id":5576,"date":"2026-05-05T14:25:20","date_gmt":"2026-05-05T05:25:20","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5576"},"modified":"2026-05-05T14:30:17","modified_gmt":"2026-05-05T05:30:17","slug":"basic-using-yaml-files","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/05\/basic-using-yaml-files\/","title":{"rendered":"[Basic]YAML\ud30c\uc77c \uc0ac\uc6a9\ud558\uae30\/Using YAML files[MacOS]"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb yaml\ud30c\uc77c\uc744 c++\uc5d0\uc11c \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<br>To use YAML files in C++, use a library.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc124\uce58 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>The installation method is as follows.<\/p>\n\n\n\n<p>\u2714\ufe0fHome Brew<\/p>\n\n\n\n<p>&#8212; \uc124\uce58\uac00 \uc644\ub8cc\ub418\uba74&nbsp;<code>\/usr\/local\/opt\/yaml-cpp<\/code>\/your version&nbsp;\ub610\ub294&nbsp;<code>\/opt\/homebrew\/opt\/yaml-cpp<\/code>&nbsp;\uacbd\ub85c\uc5d0 \ub77c\uc774\ube0c\ub7ec\ub9ac\uac00 \uc124\uce58\ub429\ub2c8\ub2e4. \uc774\ud6c4 C++ \ud504\ub85c\uc81d\ud2b8\uc5d0\uc11c \ud574\ub2f9 \uacbd\ub85c\ub97c \ud3ec\ud568\ud558\uc5ec \uc0ac\uc6a9\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.<br>Once the installation is complete, the library will be installed in the \/usr\/local\/opt\/yaml-cpp\/your version or \/opt\/homebrew\/opt\/yaml-cpp path. Afterwards, you can use it by including that path in your C++ projects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ brew install yaml-cpp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ brew install yaml-cpp\n... \uc911\uac04 \uc0dd\ub7b5 \/ skipping the middle ...\nYou have 51 outdated formulae and 2 outdated casks installed.\n\n==&gt; Fetching downloads for: yaml-cpp\n\u2714\ufe0e Bottle Manifest yaml-cpp (0.9.0)                   Downloaded    7.3KB\/  7.3KB\n\u2714\ufe0e Bottle yaml-cpp (0.9.0)                            Downloaded  131.2KB\/131.2KB\n==&gt; Pouring yaml-cpp--0.9.0.arm64_tahoe.bottle.tar.gz\n\ud83c\udf7a  <strong>\/opt\/homebrew\/Cellar\/yaml-cpp\/0.9.0<\/strong>: 51 files, 478.4KB\n==&gt; Running `brew cleanup yaml-cpp`...\nDisable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.\nHide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f github download<\/p>\n\n\n\n<p>&#8212; <a href=\"https:\/\/github.com\/jbeder\/yaml-cpp\">https:\/\/github.com\/jbeder\/yaml-cpp<\/a><\/p>\n\n\n\n<p>\u2714\ufe0f install<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/jbeder\/yaml-cpp.git\ncd yaml-cpp\nmkdir build &amp;&amp; cd build\ncmake ..\nmake\nsudo make install<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb yaml-cpp \ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58 \ud6c4 \/ After installing the yaml-cpp library<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb\ucf54\ub4dc \/ Code<\/p>\n\n\n\n<p>\u2714\ufe0f 0. \ub514\ub809\ud1a0\ub9ac \uad6c\uc870 \/ Directory Structure<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MacBookAir yaml % ls\ncmake\t\tconfig.yaml\tdefault\n\nMacBookAir cmake % ls\nbuild\t\tCMakeLists.txt\tmain.cpp\n\nMacBookAir default % ls\nmain.cpp<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f 1.\u00a0<code>yaml-cpp<\/code>\u00a0\ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58 \ubc0f \ud3ec\ud568 \/ Installing and including the yaml-cpp library<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;yaml-cpp\/yaml.h&gt;<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f 2. YAML \ud30c\uc77c \uc608\uc2dc \/ YAML file example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server:\n  host: \"localhost\"\n  port: 8080\n\ndatabase:\n  user: \"root\"\n  password: \"1234\"\n  dbname: \"testdb\"<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f 3. YAML \ud30c\uc77c \uc77d\uae30 \uc608\uc81c \ucf54\ub4dc(main.cpp)<br>YAML file reading example code (main.cpp)<\/p>\n\n\n\n<p>&#8212; cmake\ub97c \uc0ac\uc6a9\ud558\uba74 ..\/config.yaml \uc740 ..\/..\/config.yaml\uc774 \ub429\ub2c8\ub2e4.<br>If you use cmake, ..\/config.yaml becomes ..\/..\/config.yaml.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n<strong>#include &lt;yaml-cpp\/yaml.h&gt;<\/strong>\n\nint main() {\n    try {\n        <strong>YAML::Node config = YAML::LoadFile(\"..\/config.yaml\");<\/strong>\n\n        std::string host = config&#91;\"server\"]&#91;\"host\"].as&lt;std::string&gt;();\n        int port = config&#91;\"server\"]&#91;\"port\"].as&lt;int&gt;();\n\n        std::string db_user = config&#91;\"database\"]&#91;\"user\"].as&lt;std::string&gt;();\n        std::string db_password = config&#91;\"database\"]&#91;\"password\"].as&lt;std::string&gt;();\n        std::string db_name = config&#91;\"database\"]&#91;\"dbname\"].as&lt;std::string&gt;();\n\n        std::cout &lt;&lt; \"Server Host: \" &lt;&lt; host &lt;&lt; std::endl;\n        std::cout &lt;&lt; \"Server Port: \" &lt;&lt; port &lt;&lt; std::endl;\n        std::cout &lt;&lt; \"Database User: \" &lt;&lt; db_user &lt;&lt; std::endl;\n        std::cout &lt;&lt; \"Database Name: \" &lt;&lt; db_name &lt;&lt; std::endl;\n\n    } catch (const std::exception &amp;e) {\n        std::cerr &lt;&lt; \"Error loading config.yaml: \" &lt;&lt; e.what() &lt;&lt; std::endl;\n        return 1;\n    }\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling &#8211; default<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ -std=c++17 -I\/opt\/homebrew\/Cellar\/yaml-cpp\/0.9.0\/include -L\/opt\/homebrew\/Cellar\/yaml-cpp\/0.9.0\/lib -lyaml-cpp main.cpp -o main<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f\ube4c\ub4dc \/ build &#8211; cmake<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \ud504\ub85c\uc81d\ud2b8 \ub514\ub809\ud1a0\ub9ac\ub0b4\uc5d0\uc11c \uc2e4\ud589\n# Run within the project directory\n\ncd cmake\nmkdir build &amp;&amp; cd build\ncmake ..\nmake<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc2e4\ud589 \/ Run<\/p>\n\n\n\n<p>&#8212; cmake<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd project directory\/cmake\/build\n$ .\/main<\/code><\/pre>\n\n\n\n<p>&#8212; default<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd project directory\/cmake\/build\n$ .\/main<\/code><\/pre>\n\n\n\n<p> \u2714\ufe0f \uacb0\uacfc  \/ Result<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> % .\/main\nServer Host: localhost\nServer Port: 8080\nDatabase User: root\nDatabase Name: testdb<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb yaml\ud30c\uc77c\uc744 c++\uc5d0\uc11c \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.To use YAML files in C++, use a library. \ud83d\udc49\ud83c\udffb \uc124\uce58 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.The installation method is as follows. \u2714\ufe0fHome Brew &#8212; \uc124\uce58\uac00 \uc644\ub8cc\ub418\uba74&nbsp;\/usr\/local\/opt\/yaml-cpp\/your version&nbsp;\ub610\ub294&nbsp;\/opt\/homebrew\/opt\/yaml-cpp&nbsp;\uacbd\ub85c\uc5d0 \ub77c\uc774\ube0c\ub7ec\ub9ac\uac00 \uc124\uce58\ub429\ub2c8\ub2e4. \uc774\ud6c4 C++ \ud504\ub85c\uc81d\ud2b8\uc5d0\uc11c \ud574\ub2f9 \uacbd\ub85c\ub97c \ud3ec\ud568\ud558\uc5ec \uc0ac\uc6a9\ud558\uc2dc\uba74 \ub429\ub2c8\ub2e4.Once the installation is complete, the library will be installed in the \/usr\/local\/opt\/yaml-cpp\/your version or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5576","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5576"}],"version-history":[{"count":5,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5576\/revisions"}],"predecessor-version":[{"id":5581,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5576\/revisions\/5581"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}