{"id":1900,"date":"2021-08-03T11:00:29","date_gmt":"2021-08-03T03:00:29","guid":{"rendered":"https:\/\/egonlin.com\/?p=1900"},"modified":"2023-01-28T14:50:07","modified_gmt":"2023-01-28T06:50:07","slug":"%e6%a0%bc%e5%bc%8f%e5%8c%96%e8%be%93%e5%85%a5%e8%be%93%e5%87%ba","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=1900","title":{"rendered":"09 \u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa"},"content":{"rendered":"<h1>\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa<\/h1>\n<p>fmt\u5305\u5b9e\u73b0\u4e86\u7c7b\u4f3cC\u8bed\u8a00printf\u548cscanf\u7684\u683c\u5f0f\u5316I\/O\uff0c\u5bf9\u5e94\u51fd\u6570\u4e3a\uff1aPrintf\u548cScanf\u3002<\/p>\n<p>\u8be6\u89c1\uff1a<a href=\"https:\/\/golang.google.cn\/pkg\/fmt\/\">https:\/\/golang.google.cn\/pkg\/fmt\/<\/a><\/p>\n<h2>\u4e00 \u8f93\u51fa<\/h2>\n<h3>1.1 \u666e\u901a\u5360\u4f4d\u7b26<\/h3>\n<pre><code class=\"language-python\">\u5360\u4f4d\u7b26     \u8bf4\u660e                           \u4e3e\u4f8b                   \u8f93\u51fa\n%v        \u76f8\u5e94\u503c\u7684\u9ed8\u8ba4\u683c\u5f0f\u3002             Printf(&quot;%v&quot;, people)   {egon}\uff0c\n%+v       \u6253\u5370\u7ed3\u6784\u4f53\u65f6\uff0c\u4f1a\u6dfb\u52a0\u5b57\u6bb5\u540d      Printf(&quot;%+v&quot;, people)  {Name:egon}\n%#v       \u76f8\u5e94\u503c\u7684Go\u8bed\u6cd5\u8868\u793a            Printf(&quot;#v&quot;, people)   main.Human{Name:&quot;egon&quot;}\n%T        \u76f8\u5e94\u503c\u7684\u7c7b\u578b\u7684Go\u8bed\u6cd5\u8868\u793a       Printf(&quot;%T&quot;, people)   main.Human\n%%        \u5b57\u9762\u4e0a\u7684\u767e\u5206\u53f7\uff0c\u5e76\u975e\u503c\u7684\u5360\u4f4d\u7b26   Printf(&quot;%%&quot;)            %<\/code><\/pre>\n<p>\u793a\u4f8b<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main()  {\n    var x interface{} = struct {\n        name string\n        age  int\n    }{&quot;egon&quot;, 18}\n    fmt.Printf(&quot;%v\\n&quot;,x)\n    fmt.Printf(&quot;%+v\\n&quot;,x)\n    fmt.Printf(&quot;%#v\\n&quot;,x)\n    fmt.Printf(&quot;%T\\n&quot;,x)\n    fmt.Printf(&quot;%v%%\\n&quot;,100)\n}<\/code><\/pre>\n<p>\u8f93\u51fa<\/p>\n<pre><code class=\"language-go\">{egon 18}\n{name:egon age:18}\nstruct { name string; age int }{name:&quot;egon&quot;, age:18}\nstruct { name string; age int }\n100%<\/code><\/pre>\n<h3>1.2 \u5e03\u5c14\u5360\u4f4d\u7b26<\/h3>\n<pre><code class=\"language-python\">\u5360\u4f4d\u7b26       \u8bf4\u660e                \u4e3e\u4f8b                     \u8f93\u51fa\n%t          true \u6216 false       Printf(&quot;%t&quot;, true)      true<\/code><\/pre>\n<h3>1.3 \u6574\u6570\u5360\u4f4d\u7b26<\/h3>\n<pre><code class=\"language-python\">\u5360\u4f4d\u7b26     \u8bf4\u660e                                  \u4e3e\u4f8b                       \u8f93\u51fa\n%d      \u5341\u8fdb\u5236\u8868\u793a                             Printf(&quot;%d&quot;, 0x12)          18\n%b      \u4e8c\u8fdb\u5236\u8868\u793a                             Printf(&quot;%b&quot;, 5)             101\n%o      \u516b\u8fdb\u5236\u8868\u793a                             Printf(&quot;%d&quot;, 10)            12\n%x      \u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u5b57\u6bcd\u5f62\u5f0f\u4e3a\u5c0f\u5199 a-f         Printf(&quot;%x&quot;, 13)             d\n%X      \u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u5b57\u6bcd\u5f62\u5f0f\u4e3a\u5927\u5199 A-F         Printf(&quot;%x&quot;, 13)             D\n\n%c      \u76f8\u5e94Unicode\u7801\u70b9\u6240\u8868\u793a\u7684\u5b57\u7b26              Printf(&quot;%c&quot;, 0x4E2D)        \u4e2d\n%q      \u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u5b57\u9762\u503c\uff0c\u7531Go\u8bed\u6cd5\u5b89\u5168\u5730\u8f6c\u4e49 Printf(&quot;%q&quot;, 0x4E2D)       &#039;\u4e2d&#039;\n%U      Unicode\u683c\u5f0f\uff1aU+1234\uff0c\u7b49\u540c\u4e8e &quot;U+%04X&quot;     Printf(&quot;%U&quot;, 0x4E2D)       U+4E2D<\/code><\/pre>\n<p>\u793a\u4f8b<\/p><div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"1900\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"1900\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"dbe08fa5cc\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"4b85e10a16\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa fmt\u5305\u5b9e\u73b0\u4e86\u7c7b\u4f3cC\u8bed\u8a00printf\u548cscanf\u7684\u683c\u5f0f\u5316I\/O\uff0c\u5bf9\u5e94\u51fd\u6570\u4e3a\uff1aPrintf\u548cSc [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":2529,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,445],"tags":[260,261,263,262],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1900"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1900"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1900\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/2529"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}