{"id":8483,"date":"2023-01-24T01:11:38","date_gmt":"2023-01-23T17:11:38","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=8483"},"modified":"2024-05-05T14:18:34","modified_gmt":"2024-05-05T06:18:34","slug":"windows-%e4%b8%8b%e6%8e%a7%e5%88%b6%e5%8f%b0%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%b1%89%e5%ad%97%e6%89%93%e5%8d%b0","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=8483","title":{"rendered":"Windows \u4e0b\u63a7\u5236\u53f0\u7a0b\u5e8f\u7684\u6c49\u5b57\u6253\u5370"},"content":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883\uff1a<br \/>\nWindows 11 \u4e13\u4e1a\u5de5\u4f5c\u7ad9\u7248 22H2<br \/>\nVisual Studio 2022 \u4e13\u4e1a\u7248<\/p>\n<p>Windows \u4e0b\u4e2d\u6587\u4f7f\u7528\u7684 GBK \u7f16\u7801\uff0c\u6bcf\u4e2a\u6c49\u5b57\u5360\u7528 2 \u5b57\u8282\uff0c\u800c\u5728\u5fae\u8f6f\u7684 MSVC \u7f16\u8bd1\u5668\u4e2d\u5bf9\u4e8e char \u7684\u5b9e\u73b0\u76ee\u524d\u662f 1 \u5b57\u8282\uff08\u81f3\u5c11\u6211\u63a5\u89e6\u5230\u7684\u7f16\u8bd1\u5668\u76ee\u524d\u90fd\u662f 1 \u5b57\u8282\uff0c\u6bd4\u5982\u8fd8\u6709 GNU gcc\/g++\uff0c\u6807\u51c6\u89c4\u5b9a\u7684\u662f\u81f3\u5c11 1\u5b57\u8282\uff0c\u89c1\u4e0b\u56fe\uff09\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674492557794.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 767px; --smush-placeholder-aspect-ratio: 767\/71;\" \/><\/p>\n<p>\u6240\u4ee5\u5b58\u50a8\u6c49\u5b57\u7684\u65f6\u5019\u6bcf\u4e24\u4e2a\u5b57\u8282\u624d\u662f\u4e00\u4e2a\u5b57\u3002\u5982\u679c\u4f7f\u7528 wchar_t \u7684\u8bdd\uff0c\u53ef\u4ee5\u5c06\u4e24\u4e2a\u5b57\u8282\u89c6\u4e3a\u4e00\u4e2a\u5b57(\u6ce8\u610f GNU gcc\/g++ \u4e2d wchar_t \u9ed8\u8ba4\u662f 4 \u4e2a\u5b57\u8282)\u3002\u4f46\u662f\u4f7f\u7528 wchar_t \u7684\u65f6\u5019\uff0c\u6807\u51c6\u5e93\u7684\u8f93\u51fa\u51fd\u6570\u5f88\u5927\u53ef\u80fd\u4f1a\u9047\u5230\u65e0\u6cd5\u8f93\u51fa\u7684\u95ee\u9898\u3002<\/p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include &lt;Windows.h&gt;\n\nint main()\n{\n    \/\/ \u5b57\u7b26\n    const char *str = &quot;ABC \u4f60\u597d\u554a\\n&quot;;\n    printf(&quot;%s&quot;, str);\n\n    \/\/ \u5bbd\u5b57\u7b26\n    const wchar_t *wstr = L&quot;ABC \u4f60\u597d\u554a\\n&quot;;\n    wprintf(L&quot;%s&quot;, wstr); \/\/ \u6807\u51c6\u5e93\u7684\u5bbd\u5b57\u7b26\u6253\u5370\u51fd\u6570\n    WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), wstr, wcslen(wstr), NULL, NULL); \/\/ Windows API \u6253\u5370\u51fd\u6570\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674493126370.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 289px; --smush-placeholder-aspect-ratio: 289\/120;\" \/><\/p>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528 Windows API \u63d0\u4f9b\u7684 WriteConsole \u51fd\u6570\u8fdb\u884c\u6253\u5370\uff0c\u5c31\u80fd\u6b63\u5e38\u8f93\u51fa\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f20\u6807\u51c6\u8f93\u51fa\u7684\u53e5\u67c4\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u5165\u8981\u6253\u5370\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e09\u4e2a\u4f20\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u540e\u9762\u7684 NULL \u5c31\u884c\u3002<br \/>\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u53e5\u67c4\u7c7b\u4f3c\u4e8e Linux \u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5728\u63a7\u5236\u53f0\u4f7f\u7528\u65f6\u6709\u6807\u51c6\u8f93\u5165\u53e5\u67c4\u3001\u6807\u51c6\u8f93\u51fa\u53e5\u67c4\u548c\u6807\u51c6\u9519\u8bef\u53e5\u67c4\uff0c\u5bf9\u5e94 Linux \u4e0b\u7ec8\u7aef\u4f7f\u7528\u65f6\u7684\u6807\u51c6\u8f93\u5165\u6587\u4ef6\u63cf\u8ff0\u7b26\u3001\u6807\u6ce8\u8f93\u51fa\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u6807\u51c6\u9519\u8bef\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002<br \/>\n\u8fd9\u4e2a\u53e5\u67c4(\u6216\u6587\u4ef6\u63cf\u8ff0\u7b26)\u5c31\u5bf9\u5e94\u7740 Windows \u63a7\u5236\u53f0\uff08\u6216 Linux \u7ec8\u7aef\uff09\u7684\u8f93\u51fa\u8f93\u5165\uff0c\u8981\u663e\u793a\u4ec0\u4e48\u5c31\u4f7f\u7528\u6807\u51c6\u8f93\u51fa\uff0c\u8981\u4ece\u63a7\u5236\u53f0\uff08\u6216\u7ec8\u7aef\uff09\u8bfb\u53d6\u5c31\u4f7f\u7528\u6807\u51c6\u8f93\u5165\u53e5\u67c4\uff08\u6216\u6807\u51c6\u8f93\u5165\u6587\u4ef6\u63cf\u8ff0\u7b26\uff09\uff0c\u6253\u5370\u9519\u8bef\u4fe1\u606f\u5c31\u4f7f\u7528\u6807\u51c6\u9519\u8bef\u3002<br \/>\nLinux \u4e0b\u7684\u6807\u51c6\u9519\u8bef\u8bb0\u5f97\u662f\u65e0\u7f13\u51b2\u8f93\u51fa\uff0c\u53ef\u4ee5\u76f4\u63a5\u8f93\u51fa\u5230\u7ec8\u7aef\uff0c\u800c\u6807\u51c6\u8f93\u51fa\u5219\u662f\u5148\u653e\u5230\u7f13\u51b2\u533a\uff0c\u5728\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u65f6\u624d\u5237\u65b0\u5230\u7ec8\u7aef\uff0c\u6bd4\u5982\u6362\u884c\u7b26\uff0c\u7f13\u51b2\u533a\u6ee1\u4e86\u4ee5\u53ca\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\u3002\u4f30\u8ba1\u7740 Windows \u7684\u8fd9\u4e2a\u4e5f\u5dee\u4e0d\u591a\u5427\uff0c\u6211\u662f\u624d\u5f00\u59cb\u5b66\u4e60 Windows API\uff0c\u8fd8\u4e0d\u662f\u5f88\u4e86\u89e3\u673a\u5236\uff0c\u73b0\u5728\u4e5f\u662f\u8fb9\u5b66\u8fb9\u8bb0\u5f55\u4e00\u4e9b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883\uff1a Windows 11 \u4e13\u4e1a\u5de5\u4f5c\u7ad9\u7248 22H2 Visual Studio 2022 \u4e13\u4e1a\u7248 Win [&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":"","_lmt_disable":"","footnotes":""},"categories":[1,593],"tags":[],"class_list":["post-8483","post","type-post","status-publish","format-standard","hentry","category-all","category-windows-api"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8483","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=8483"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8483\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}