{"id":16897,"date":"2024-08-07T00:13:59","date_gmt":"2024-08-06T16:13:59","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=16897"},"modified":"2024-08-07T07:57:14","modified_gmt":"2024-08-06T23:57:14","slug":"vs-%ef%bc%88msvc%ef%bc%89c-%e4%b8%ad%e4%bd%bf%e7%94%a8-c-%e8%af%ad%e8%a8%80%e7%9a%84%e6%95%b0%e5%ad%a6%e5%b8%b8%e9%87%8f","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=16897","title":{"rendered":"C++ \u4e2d\u4f7f\u7528 C \u8bed\u8a00\u7684\u6570\u5b66\u5e38\u91cf"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=16897\/#%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\" >\u6d4b\u8bd5\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=16897\/#%E7%A0%94%E7%A9%B6\" >\u7814\u7a76<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\"><\/span>\u6d4b\u8bd5\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Windows 11 + VS 2022\uff08MSVC\uff09<br \/>\nUbuntu 24.04 + GNU 13.2.0\uff08g++\uff09<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E7%A0%94%E7%A9%B6\"><\/span>\u7814\u7a76<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>C \u8bed\u8a00\u7684 <strong>math.h<\/strong> \u5934\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6570\u5b66\u5e38\u91cf\uff0c\u8fd9\u662f\u4e00\u4e2a\u6807\u51c6\u5e93\u3002C \u8bed\u8a00\u7684\u6807\u51c6\u5e93\u5728 C++ \u4e2d\u901a\u5e38\u63d0\u4f9b\u4e86\u9002\u914d\u7684\u5934\u6587\u4ef6\uff0c\u547d\u540d\u4e3a <strong>C<\/strong> + C\u6807\u51c6\u5e93\u540d + \u53bb\u6389.h\u3002math.h \u5728 C++ \u4e2d\u4f7f\u7528\uff0c\u53ef\u4ee5\u5f15\u7528 <strong>cmath<\/strong> \u8fd9\u4e2a\u5934\u6587\u4ef6\u3002<\/p>\n<p>\u4f7f\u7528 GNU \u7f16\u8bd1\u4e0b\u9762\u4ee3\u7801<\/p>\n<pre><code class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;cmath&gt;\n\nint main()\n{\n    std::cout &lt;&lt; M_PI &lt;&lt; std::endl;\n}<\/code><\/pre>\n<p>\u7f16\u8bd1\u6210\u529f\uff0c\u8fd0\u884c\u6b63\u5e38<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722959920821.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 429px; --smush-placeholder-aspect-ratio: 429\/99;\" \/><\/p>\n<p>\u7136\u800c\u540c\u6837\u7684\u4ee3\u7801\u4f7f\u7528 VS \u7f16\u8bd1\u5c31\u62a5\u9519\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722959972651.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 394px; --smush-placeholder-aspect-ratio: 394\/174;\" \/><\/p>\n<p>\u4e8e\u662f\u5bf9\u5e38\u91cf\u7684\u5b9a\u4e49\u8fdb\u884c\u8ffd\u8e2a\u53d1\u73b0\u5f15\u7528\u5173\u7cfb\u4e3a\uff1acmath-&gt;cstdlib-&gt;math.h-&gt;corecrt_math_defines.h<br \/>\ncorecrt_math_defines.h \u4e2d\u5b9a\u4e49\u4e86\u6570\u5b66\u5e38\u91cf<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960097883.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 661px; --smush-placeholder-aspect-ratio: 661\/680;\" \/><\/p>\n<p>\u4f46\u662f math.h \u5f15\u7528 corecrt_math_defines.h \u662f\u6709\u6761\u4ef6\u7684<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960137310.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 670px; --smush-placeholder-aspect-ratio: 670\/324;\" \/><\/p>\n<p>\u9700\u8981\u5b9a\u4e49 <strong>_USE_MATH_DEFINES<\/strong> \u624d\u4f1a\u5f15\u7528\uff0c\u4e8e\u662f\u4ee3\u7801\u6dfb\u52a0\u4e86\u8fd9\u4e2a\u5b9a\u4e49<\/p>\n<pre><code class=\"language-cpp\">#define _USE_MATH_DEFINES\n#include &lt;iostream&gt;\n#include &lt;cmath&gt;\n\nint main()\n{\n    std::cout &lt;&lt; M_PI &lt;&lt; std::endl;\n}<\/code><\/pre>\n<p>\u80fd\u6210\u529f\u8fd0\u884c\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960231991.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1076px; --smush-placeholder-aspect-ratio: 1076\/383;\" \/><\/p>\n<p>\u4f46\u662f\u5982\u679c\u628a\u4ee3\u7801\u6539\u6210\u4e86<\/p>\n<pre><code class=\"language-cpp\">#include &lt;iostream&gt;\n#define _USE_MATH_DEFINES\n#include &lt;cmath&gt;\n\nint main()\n{\n    std::cout &lt;&lt; M_PI &lt;&lt; std::endl;\n}<\/code><\/pre>\n<p>\u53c8\u8bf4\u627e\u4e0d\u5230 M_PI \u4e86\uff0c\u90a3\u4e48\u5c31\u8003\u8651\u662f iostream \u4e2d\u5176\u5b9e\u4e5f\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u5f15\u7528\u4e86 cmath\uff0c\u7b49\u4e8e\u7b2c\u4e00\u6b21\u5f15\u7528 cmath \u53d1\u751f\u5728\u5b9a\u4e49 _USE_MATH_DEFINES  \u4e4b\u524d\uff0c\u540e\u9762\u6211\u518d\u5f15\u7528\u7684\u5df2\u7ecf\u65e0\u6548\u4e86\uff0c\u4e8e\u662f\u6d4b\u8bd5<\/p>\n<pre><code class=\"language-cpp\">#define _USE_MATH_DEFINES\n#include &lt;iostream&gt;\n\nint main()\n{\n    std::cout &lt;&lt; M_PI &lt;&lt; std::endl;\n}<\/code><\/pre>\n<p>\u53ef\u4ee5\u7f16\u8bd1\u8fd0\u884c\uff0c\u8bc1\u660e iostream \u4e2d\u5df2\u7ecf\u76f4\u63a5\u6216\u95f4\u63a5\u5f15\u7528\u4e86 cmath\u3002\u90a3\u4e48\u8981\u4fdd\u8bc1\u6570\u5b66\u5e38\u91cf\u80fd\u6b63\u5e38\u4f7f\u7528\uff0c\u5c31\u9700\u8981\u4fdd\u8bc1 _USE_MATH_DEFINES \u5b9a\u4e49\u5728\u6700\u524d\u9762\uff0c\u5b9e\u9645\u5f00\u53d1\u4e2d\u5f15\u7528\u7684\u5e93\u975e\u5e38\u591a\uff0c\u4e0d\u80fd\u4fdd\u8bc1\u522b\u7684\u5934\u6587\u4ef6\u5c31\u6ca1\u6709\u5f15\u7528 cmath\u3002\u518d\u4e00\u60f3\uff0c\u8fd9\u8fd8\u662f\u5355\u6587\u4ef6\uff0c\u53ea\u8981\u653e\u5728\u6700\u524d\u9762\u4e00\u5b9a\u4fdd\u8bc1\u5b9a\u4e49\u6709\u6548\uff0c\u5982\u679c\u662f\u591a\u6e90\u6587\u4ef6\uff0c\u5f15\u7528\u7684\u5173\u7cfb\u5c31\u975e\u5e38\u590d\u6742\u4e86\uff0c\u9700\u8981\u653e\u7f6e\u5728\u6240\u6709\u6e90\u7801\u7684\u7b2c\u4e00\u6b21\u5f15\u7528 cmath \u7684\u524d\u9762\u7684\u624d\u6709\u6548\u3002<br \/>\n\u6700\u597d\u7684\u529e\u6cd5\u5c31\u662f\u9879\u76ee\u5c5e\u6027\uff0c\u653e\u7f6e\u5230\u9884\u5904\u7406\u5668\u4e2d\uff0c\u8fd9\u6837\u5c31\u662f\u7f16\u8bd1\u5668\u4e00\u5f00\u59cb\u5c31\u7ed9\u52a0\u4e0a\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960732303.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 359px; --smush-placeholder-aspect-ratio: 359\/814;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960694600.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 790px; --smush-placeholder-aspect-ratio: 790\/607;\" \/><\/p>\n<p>\u6e90\u6587\u4ef6\u4e2d\u4e0d\u9700\u8981\u6dfb\u52a0\u5b9a\u4e49\u4e86\uff0c\u4e5f\u80fd\u4fdd\u8bc1\u6b63\u5e38\u5f15\u7528<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2024\/08\/image-1722960785462.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 388px; --smush-placeholder-aspect-ratio: 388\/260;\" \/><\/p>\n<p>\u8fd9\u4e2a\u5c5e\u4e8e\u662f\u7f16\u8bd1\u5668\u5185\u90e8\u5b9e\u73b0\u7684\u5dee\u5f02\uff0cVS \u9700\u8981\u7528 _USE_MATH_DEFINES \u6765\u63a7\u5236\u662f\u5426\u5f15\u7528\u6570\u5b66\u5e38\u91cf\uff0c\u800c GNU \u662f\u76f4\u63a5\u5f15\u7528\u7684\u3002\u7b97\u662f\u5404\u6709\u4f18\u52a3\uff0c\u5bf9\u4e8e\u4e0d\u6e05\u695a\u60c5\u51b5\u7684\uff0c\u5728 VS \u91cc\u9047\u5230\u5c31\u6709\u4e00\u70b9\u61f5\uff0c\u4f1a\u60f3\u660e\u660e GNU \u91cc\u90fd\u80fd\u76f4\u63a5\u7528\u7684\uff08\u6211\u7b2c\u4e00\u6b21\u9047\u5230\u7684\u65f6\u5019\u5c31\u662f\u8fd9\u6837\uff09\uff0c\u4f46\u662f\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u907f\u514d\u547d\u540d\u7a7a\u95f4\u6c61\u67d3\uff0c\u6709\u4e9b\u9879\u76ee\u91cc\u53ef\u80fd\u81ea\u5df1\u5b9a\u4e49\u4e86\u540c\u540d\u7684\u6807\u8bc6\u7b26\u4f1a\u4ea7\u751f\u51b2\u7a81\uff0c\u901a\u8fc7\u6761\u4ef6\u63a7\u5236\u662f\u5426\u5f15\u7528\uff0c\u9ed8\u8ba4\u4e0d\u5f15\u7528\uff0c\u8fd9\u6837\u5c31\u907f\u514d\u91cd\u540d\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883 Windows 11 + VS 2022\uff08MSVC\uff09 Ubuntu 24.04 + GNU 13.2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,589,594],"tags":[],"class_list":["post-16897","post","type-post","status-publish","format-standard","hentry","category-all","category-c-c","category-594"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/16897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16897"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/16897\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}