{"id":1106,"date":"2018-05-21T14:04:36","date_gmt":"2018-05-21T14:04:36","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=1106"},"modified":"2024-02-16T10:26:37","modified_gmt":"2024-02-16T10:26:37","slug":"more-functionality-needed-c","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=1106","title":{"rendered":"Operating System APIs (C++)"},"content":{"rendered":"<p>Before using the OS APIs directly, take a look if the STL or boost already provides this functionality. Also be aware for a cross-platform software you have to implement it for all of them separately.<\/p>\n<hr>\n<p><strong>Example<\/strong> (File system access)<\/p>\n<pre class=\"brush: cpp; gutter: false; title: POSIX; notranslate\" title=\"POSIX\">\r\n#include &lt;sys\/types.h&gt;\r\n#include &lt;dirent.h&gt;\r\n\r\nvoid listFiles(const std::string&amp; folder, std::vector&lt;std::string&gt;&amp; files)\r\n{\r\n   DIR* posDir = opendir(folder.c_str());\r\n   struct dirent* data;\r\n\r\n   while ((data = readdir(posDir)) != NULL) {\r\n      files.push_back(data-&gt;d_name);\r\n   }\r\n\r\n   closedir(posDir);\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; gutter: false; title: WinAPI; notranslate\" title=\"WinAPI\">\r\n#include &lt;windows.h&gt;\r\n \r\nvoid listFiles(const std::string&amp; folder, std::vector&lt;std::string&gt;&amp; files)\r\n{\r\n   std::string regEx(folder + &quot;\\\\*&quot;);\r\n   WIN32_FIND_DATA data;\r\n   HANDLE hdl;\r\n\r\n   if ((hdl = FindFirstFile(regEx.c_str(), &amp;data)) != INVALID_HANDLE_VALUE)\r\n   {\r\n      do {\r\n         files.push_back(data.cFileName);\r\n      } while (FindNextFile(hdl, &amp;data) != 0);\r\n\r\n      FindClose(hdl);\r\n   }\r\n}\r\n<\/pre>\n<p>That scenario for example is already implemented in boost for a long time and got into the STL since C++17.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before using the OS APIs directly, take a look if the STL or boost already provides this functionality. Also be<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1106"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1106"}],"version-history":[{"count":2,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1106\/revisions"}],"predecessor-version":[{"id":16438,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1106\/revisions\/16438"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1106"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}