{"id":223,"date":"2011-05-05T21:51:14","date_gmt":"2011-05-05T13:51:14","guid":{"rendered":"http:\/\/blog.mega-zone.org\/?p=223"},"modified":"2011-05-05T21:59:51","modified_gmt":"2011-05-05T13:59:51","slug":"%e4%b8%ba%e7%a5%9e%e9%a9%ac%e4%b8%8d%e8%a6%81%e5%9c%a8%e4%bb%a3%e7%a0%81%e9%87%8c%e5%86%99%e4%b8%ad%e6%96%87%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.mega-zone.org\/?p=223","title":{"rendered":"\u4e3a\u795e\u9a6c\u4e0d\u8981\u5728\u4ee3\u7801\u91cc\u5199\u4e2d\u6587\uff08\u4e00\uff09"},"content":{"rendered":"<p>c++\u4e2d\u7684\u5b57\u7b26\u4e32\u662f\u4e2a\u5f88\u9ebb\u70e6\u7684\u4e1c\u897f\uff0c\u6709\u4e86\u5bbd\u5b57\u7b26\u4e4b\u540e\u53d8\u5f97\u66f4\u52a0\u9ebb\u70e6\uff0c\u636e\u8bf4c++0x\u8981\u5f15\u5165raw string\uff0c\u5c31\u662f\u7c7b\u4f3c\u8fd9\u79cd<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">const char* str = R&quot;\u567c\u91cc\r\n\r\n\u56de\u4e2a\u8f66\r\n\r\n\u556a\u5566&quot;;<\/pre>\n<p>\u7684\u5954\u653e\u5199\u6cd5\uff0c\u6240\u4ee5\u672a\u6765\u4f30\u8ba1\u4f1a\u66f4\u52a0\u7684\u4e71\u3002\u6700\u8fd1\u770b\u4e86\u4e00\u4e9b\u5173\u4e8e\u5b57\u7b26\u4e32\u7f16\u7801\u7684\u4e1c\u897f\uff0c\u624d\u660e\u767d\u53cc\u5f15\u53f7\u4e4b\u95f4\u7684\u8fd9\u4e9b\u73a9\u610f\u513f\u8fd8\u662f\u6709\u5f88\u591a\u8bf4\u9053\u7684\uff0c\u63a5\u4e0b\u6765\u8be6\u7ec6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u8981\u662f\u8bf4\u9519\u4e86\uff0c\u90a3\u5c31\u65e5\u540e\u53d1\u73b0\u518d\u6539= =b<\/p>\n<p>\u53cc\u5f15\u53f7\u641e\u51fa\u6765\u7684\u8fd9\u79cd\u5b57\u7b26\u4e32\u79f0\u4e3astring literal\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2aconst char*\u6216\u8005const wchar_t*\u3002vc\u7684\u7f16\u8bd1\u5668\uff08\u4f30\u8ba1\u5927\u90e8\u5206\u90fd\u6709\uff09\u6709\u4e2a\u4f18\u5316\uff0c\u53ebstring pool\uff0c\u662f\u8bf4\u7f16\u8bd1\u7684\u65f6\u5019\u6240\u6709\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u4f1a\u88ab\u5408\u5e76\uff0c\u53ea\u4fdd\u7559\u4e00\u4efd\u5728\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u76f8\u540c\u7684string literal\u4f1a\u8fd4\u56de\u76f8\u540c\u7684\u6307\u9488\u3002<\/p>\n<p>\u4f46\u662f\u53ea\u8981\u6709\u5b57\u7b26\u5c31\u4f1a\u7275\u626f\u5230\u5b57\u7b26\u7f16\u7801\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u53ea\u5b58\u53d6byte\uff0c\u5199\u5728\u5f15\u53f7\u4e4b\u95f4\u7684\u5b57\u7b26\u5bf9\u5e94\u54ea\u4e9bbyte\u5462\uff1f\u53e6\u5916\uff0c\u4ee3\u7801\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u4e5f\u5b58\u5728\u7f16\u7801\u7684\u95ee\u9898\uff0c\u8fd9\u4e8c\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\u53c8\u662f\u5982\u4f55\u5462\uff1f\u8bf7\u4e0d\u8981\u8d70\u5f00\uff0c\u6211\u4eec\u5e7f\u544a\u4e4b\u540e\u518d\u8fdb\u884c\u8ba8\u8bba\u2026\u2026<\/p>\n<p><strong><em>\u8de8\u5e73\u53f0\u79fb\u690d\u523b\u4e0d\u5bb9\u7f13\u2026\u2026\u7a0b\u5e8f\u4e2d\u60ca\u73b0\u795e\u79d8\u5b57\u4e32\u2026\u2026\u7a76\u7adf\u662f\u7a0b\u5e8f\u5458\u8111\u6b8b\u8fd8\u662f\u7f16\u8bd1\u5668\u8111\u6b8b\u2026\u2026\u7b54\u6848\u5373\u5c06\u63ed\u6653\uff0c\u8bf7\u770b\u8d70\u8fdb\u79d1\u5b66\u4e4b\u300a\u4e0d\u8981\u5728\u4ee3\u7801\u4e2d\u5199\u4e2d\u6587\u300b\u2026\u2026<\/em><\/strong><\/p>\n<p>\u55ef\u55ef\uff0c\u5e7f\u544a\u5b8c\u6bd5\uff0c\u7b54\u6848\u662f~~~~~~\u8fd9\u5f97\u770b\u7528\u7684\u4ec0\u4e48\u7f16\u8bd1\u5668\u4e86\u256e(\u256f_\u2570)\u256d<\/p>\n<p>\u6211\u5199\u4e86\u6bb5\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6253\u5370string literal\u7684\u5404\u4e2abyte\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nvoid outbyte(const void* buf, int len)\r\n{\r\n\tunsigned char* p = (unsigned char*)buf;\r\n\tcout&lt;&lt;&quot;Len:&quot;&lt;&lt;len&lt;&lt;endl;\r\n\twhile(len--)\r\n\t{\r\n\t\tcout&lt;&lt;hex&lt;&lt;(int)(*p++)&lt;&lt;&quot; &quot;;\r\n\t}\r\n\tcout&lt;&lt;endl;\r\n}\r\n\r\nint main(int argc, char** argv)\r\n{\r\n\tconst char* p = &quot;a\u597d\u4eba&quot;;\r\n\toutbyte(p, sizeof(&quot;a\u597d\u4eba&quot;));\r\n\r\n\tconst wchar_t* pw = L&quot;a\u597d\u4eba&quot;;\r\n\toutbyte(pw, sizeof(L&quot;a\u597d\u4eba&quot;));\r\n\r\n\treturn 0;\r\n}<\/pre>\n<p>\u4ee3\u7801\u5206\u522b\u4fdd\u5b58\u6210\u4e0d\u540c\u7684\u7f16\u7801\u683c\u5f0f\uff0c\u6709utf-8, \u4ee5BOM(byte order mark)\u5f00\u5934\u7684utf-8\uff0c\u8fd8\u6709gbk\u3002\u7136\u540e\u7528gcc4\uff0cvc6\uff0cvc2003\uff0cvc2005\u4ee5\u53cavc2008\u7f16\u8bd1\u5e76\u8fd0\u884c\uff0c\u5f97\u5230\u4e86\u5f88\u6709\u8da3\uff08\u86cb\u75bc\uff1f\uff09\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u55ef\u55ef\uff0c\u7ed3\u679c\u548c\u5206\u6790\u5c31\u660e\u5929\u518d\u8d34\u4e86= =b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>c++\u4e2d\u7684\u5b57\u7b26\u4e32\u662f\u4e2a\u5f88\u9ebb\u70e6\u7684\u4e1c\u897f\uff0c\u6709\u4e86\u5bbd\u5b57\u7b26\u4e4b\u540e\u53d8\u5f97\u66f4\u52a0\u9ebb\u70e6\uff0c\u636e\u8bf4c++0x\u8981\u5f15\u5165raw string\uff0c\u5c31\u662f\u7c7b\u4f3c\u8fd9\u79cd const char* str = R&quot;\u567c\u91cc \u56de\u4e2a\u8f66 \u556a\u5566&quot;; \u7684\u5954\u653e\u5199\u6cd5\uff0c\u6240\u4ee5\u672a\u6765\u4f30\u8ba1\u4f1a\u66f4\u52a0\u7684\u4e71\u3002\u6700\u8fd1\u770b\u4e86\u4e00\u4e9b\u5173\u4e8e\u5b57\u7b26\u4e32\u7f16\u7801\u7684\u4e1c\u897f\uff0c\u624d\u660e\u767d\u53cc\u5f15\u53f7\u4e4b\u95f4\u7684\u8fd9\u4e9b\u73a9\u610f\u513f\u8fd8\u662f\u6709\u5f88\u591a\u8bf4\u9053\u7684\uff0c\u63a5\u4e0b\u6765\u8be6\u7ec6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u8981\u662f\u8bf4\u9519\u4e86\uff0c\u90a3\u5c31\u65e5\u540e\u53d1\u73b0\u518d\u6539= =b \u53cc\u5f15\u53f7\u641e\u51fa\u6765\u7684\u8fd9\u79cd\u5b57\u7b26\u4e32\u79f0\u4e3astring literal\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2aconst char*\u6216\u8005const wchar_t*\u3002vc\u7684\u7f16\u8bd1\u5668\uff08\u4f30\u8ba1\u5927\u90e8\u5206\u90fd\u6709\uff09\u6709\u4e2a\u4f18\u5316\uff0c\u53ebstring pool\uff0c\u662f\u8bf4\u7f16\u8bd1\u7684\u65f6\u5019\u6240\u6709\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u4f1a\u88ab\u5408\u5e76\uff0c\u53ea\u4fdd\u7559\u4e00\u4efd\u5728\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u76f8\u540c\u7684string literal\u4f1a\u8fd4\u56de\u76f8\u540c\u7684\u6307\u9488\u3002 \u4f46\u662f\u53ea\u8981\u6709\u5b57\u7b26\u5c31\u4f1a\u7275\u626f\u5230\u5b57\u7b26\u7f16\u7801\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u53ea\u5b58\u53d6byte\uff0c\u5199\u5728\u5f15\u53f7\u4e4b\u95f4\u7684\u5b57\u7b26\u5bf9\u5e94\u54ea\u4e9bbyte\u5462\uff1f\u53e6\u5916\uff0c\u4ee3\u7801\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u4e5f\u5b58\u5728\u7f16\u7801\u7684\u95ee\u9898\uff0c\u8fd9\u4e8c\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\u53c8\u662f\u5982\u4f55\u5462\uff1f\u8bf7\u4e0d\u8981\u8d70\u5f00\uff0c\u6211\u4eec\u5e7f\u544a\u4e4b\u540e\u518d\u8fdb\u884c\u8ba8\u8bba\u2026\u2026 \u8de8\u5e73\u53f0\u79fb\u690d\u523b\u4e0d\u5bb9\u7f13\u2026\u2026\u7a0b\u5e8f\u4e2d\u60ca\u73b0\u795e\u79d8\u5b57\u4e32\u2026\u2026\u7a76\u7adf\u662f\u7a0b\u5e8f\u5458\u8111\u6b8b\u8fd8\u662f\u7f16\u8bd1\u5668\u8111\u6b8b\u2026\u2026\u7b54\u6848\u5373\u5c06\u63ed\u6653\uff0c\u8bf7\u770b\u8d70\u8fdb\u79d1\u5b66\u4e4b\u300a\u4e0d\u8981\u5728\u4ee3\u7801\u4e2d\u5199\u4e2d\u6587\u300b\u2026\u2026 \u55ef\u55ef\uff0c\u5e7f\u544a\u5b8c\u6bd5\uff0c\u7b54\u6848\u662f~~~~~~\u8fd9\u5f97\u770b\u7528\u7684\u4ec0\u4e48\u7f16\u8bd1\u5668\u4e86\u256e(\u256f_\u2570)\u256d \u6211\u5199\u4e86\u6bb5\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6253\u5370string literal\u7684\u5404\u4e2abyte\uff1a #include &lt;iostream&gt; using namespace std; void outbyte(const void* buf, int len) { unsigned char* p = (unsigned char*)buf; cout&lt;&lt;&quot;Len:&quot;&lt;&lt;len&lt;&lt;endl; while(len&#8211;) { cout&lt;&lt;hex&lt;&lt;(int)(*p++)&lt;&lt;&quot; &quot;; } cout&lt;&lt;endl; } int main(int argc, char** argv) { const &hellip; <a href=\"https:\/\/blog.mega-zone.org\/?p=223\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u4e3a\u795e\u9a6c\u4e0d\u8981\u5728\u4ee3\u7801\u91cc\u5199\u4e2d\u6587\uff08\u4e00\uff09&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[12],"_links":{"self":[{"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/posts\/223"}],"collection":[{"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":8,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mega-zone.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}