{"id":301293,"date":"2024-05-20T18:04:37","date_gmt":"2024-05-20T10:04:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/301293.html"},"modified":"2024-05-20T18:04:51","modified_gmt":"2024-05-20T10:04:51","slug":"c-c-%e6%9c%89%e4%bb%80%e4%b9%88%e9%9d%9e%e5%b8%b8%e5%a5%bd%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e5%a4%84%e7%90%86%e5%ba%93%e5%90%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/301293.html","title":{"rendered":"c\/c  \u6709\u4ec0\u4e48\u975e\u5e38\u597d\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\u5417"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26213507\/208d50f9-2312-4ba9-adf0-ff7a061554df.webp\" alt=\"c\/c  \u6709\u4ec0\u4e48\u975e\u5e38\u597d\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\u5417\" \/><\/p>\n<p><p>\u5728C\/C++\u4e2d\uff0c\u6709\u591a\u79cd\u975e\u5e38\u597d\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u7b80\u5316\u548c\u52a0\u901f\u5f00\u53d1\u8fc7\u7a0b\u3002\u8fd9\u4e9b\u5e93\u5305\u62ec<strong>\u6807\u51c6\u5e93 <code>&lt;cstring&gt;<\/code>\u3001Boost\u5e93\u7684\u5b57\u7b26\u4e32\u5904\u7406\u90e8\u5206\u3001\u4ee5\u53caICU (International Components for Unicode) \u5e93\u3002<\/strong> \u5728\u8fd9\u4e9b\u5e93\u5f53\u4e2d\uff0c<strong>ICU<\/strong>\u56e0\u5176\u529f\u80fd\u5f3a\u5927\u3001\u652f\u6301\u5e7f\u6cdb\u7684Unicode\u7279\u6027\u548c\u56fd\u9645\u5316\u529f\u80fd\u800c\u683c\u5916\u7a81\u51fa\u3002<\/p>\n<\/p>\n<p><p>ICU \u4e3b\u8981\u63d0\u4f9b\u5168\u9762\u7684\u5b57\u7b26\u96c6\u8f6c\u6362\u529f\u80fd\u3001Unicode\u6587\u672c\u5904\u7406\u80fd\u529b\u3001\u56fd\u9645\u5316\u652f\u6301\u7b49\u3002\u8fd9\u4f7f\u5f97\u5b83\u4e0d\u4ec5\u9002\u7528\u4e8e\u5904\u7406\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c\u5982\u641c\u7d22\u3001\u62f7\u8d1d\u3001\u62fc\u63a5\uff0c\u8fd8\u80fd\u5f88\u597d\u5730\u652f\u6301\u590d\u6742\u7684\u6587\u672c\u5904\u7406\u9700\u6c42\uff0c\u6bd4\u5982\u6587\u672c\u5206\u5272\u3001\u672c\u5730\u5316\u6bd4\u8f83\u548cUnicode\u6807\u51c6\u7684\u652f\u6301\u7b49\u3002\u8fd9\u4e00\u7279\u6027\u5c24\u5176\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u591a\u79cd\u8bed\u8a00\u6587\u672c\u7684\u56fd\u9645\u5316\u8f6f\u4ef6\u9879\u76ee\u3002\u56e0\u6b64\uff0cICU \u4e0d\u4ec5\u662f\u5904\u7406\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u4e5f\u662f\u8fdb\u884c\u56fd\u9645\u5316\u548c\u672c\u5730\u5316\u5f00\u53d1\u7684\u91cd\u8981\u57fa\u77f3\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001STANDARD LIBRARY <code>&lt;CSTRING&gt;<\/code><\/h3>\n<\/p>\n<p><p>\u5728C\u548cC++\u5f00\u53d1\u4e2d\uff0c\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u4e00\u5957\u57fa\u672c\u7684\u5b57\u7b26\u4e32\u5904\u7406\u529f\u80fd\uff0c\u8fd9\u4e00\u7cfb\u5217\u529f\u80fd\u5305\u542b\u5728<code>&lt;cstring&gt;<\/code> (\u5728C\u8bed\u8a00\u4e2d\u4e3a<code>&lt;string.h&gt;<\/code>)\u5e93\u4e2d\u3002\u8fd9\u4e2a\u5e93\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u64cd\u4f5cnull-terminated C\u5b57\u7b26\u4e32\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5b57\u7b26\u4e32\u6bd4\u8f83\uff1a<code>strcmp<\/code>\u51fd\u6570\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u503c\u6307\u793a\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u76f8\u5bf9\u987a\u5e8f\u3002<\/li>\n<li>\u5b57\u7b26\u4e32\u62f7\u8d1d\uff1a<code>strcpy<\/code>\u548c<code>strncpy<\/code>\u51fd\u6570\u7528\u4e8e\u590d\u5236\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u5b57\u7b26\u4e32\u957f\u5ea6\uff1a<code>strlen<\/code>\u51fd\u6570\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff08\u4e0d\u5305\u62ecnull terminator\uff09\u3002<\/li>\n<\/ul>\n<p><p>\u5c3d\u7ba1<code>&lt;cstring&gt;<\/code>\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u5b57\u7b26\u4e32\u5904\u7406\u80fd\u529b\uff0c\u4f46\u5728\u5904\u7406\u590d\u6742\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u6216\u9700\u8981\u66f4\u9ad8\u6548\u7387\u7684\u573a\u5408\uff0c\u53ef\u80fd\u4e0d\u591f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001BOOST\u5e93\u7684\u5b57\u7b26\u4e32\u5904\u7406\u90e8\u5206<\/h3>\n<\/p>\n<p><p>Boost\u5e93\u4f5c\u4e3aC++\u7684\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u63d0\u4f9b\u4e86\u975e\u5e38\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u5b57\u7b26\u4e32\u5904\u7406\u90e8\u5206\u662f\u975e\u5e38\u5b9e\u7528\u7684\u4e00\u90e8\u5206\u3002\u5b83\u4e0d\u4ec5\u8986\u76d6\u4e86\u6807\u51c6\u5e93\u7684\u529f\u80fd\uff0c\u8fd8\u63d0\u4f9b\u4e86\u66f4\u52a0\u4e30\u5bcc\u7075\u6d3b\u7684\u63a5\u53e3\u548c\u529f\u80fd\u3002<\/p>\n<\/p>\n<ul>\n<li>Boost.StringAlgorithms\u5e93\uff1a\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u5904\u7406\u7b97\u6cd5\uff0c\u4f8b\u5982<code>split<\/code>\u3001<code>join<\/code>\u3001<code>trim<\/code>\u7b49\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u5b57\u7b26\u4e32\u7684\u5904\u7406\u903b\u8f91\u3002<\/li>\n<li>Boost.Regex\u5e93\uff1a\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u5904\u7406\u5b57\u7b26\u4e32\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u7684\u5339\u914d\u3001\u641c\u7d22\u548c\u66ff\u6362\u7b49\u64cd\u4f5c\u3002\u8fd9\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u5e76\u4e14\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u5904\u7406\u590d\u6742\u7684\u5b57\u7b26\u4e32\u6a21\u5f0f\u8bc6\u522b\u548c\u6587\u672c\u5206\u6790\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001ICU (INTERNATIONAL COMPONENTS FOR UNICODE) \u5e93<\/h3>\n<\/p>\n<p><p>ICU \u662f\u4e00\u4e2a\u6210\u719f\u7684\u3001\u5e7f\u6cdb\u652f\u6301Unicode\u7684C\/C++\u548cJava\u5e93\uff0c\u7279\u522b\u9002\u5408\u4e8e\u5f00\u53d1\u9700\u8981\u8003\u8651\u5230\u56fd\u9645\u5316\uff08I18N\uff09\u548c\u672c\u5730\u5316\uff08L10N\uff09\u9700\u6c42\u7684\u8f6f\u4ef6\u3002<\/p>\n<\/p>\n<ul>\n<li>Unicode\u652f\u6301\uff1a\u63d0\u4f9b\u5168\u9762\u7684Unicode\u548c\u5b57\u7b26\u96c6\u652f\u6301\u529f\u80fd\uff0c\u53ef\u4ee5\u8fdb\u884c\u5b57\u7b26\u7f16\u7801\u7684\u8f6c\u6362\u548c\u5904\u7406\u3002<\/li>\n<li>\u590d\u6742\u6587\u672c\u5904\u7406\uff1a\u652f\u6301\u591a\u79cd\u8bed\u8a00\u7684\u590d\u6742\u6587\u672c\u5e03\u5c40\u548c\u65ad\u884c\uff0c\u6587\u672c\u8fb9\u754c\u7684\u68c0\u6d4b\u7b49\u3002<\/li>\n<li>\u672c\u5730\u5316\u652f\u6301\uff1a\u652f\u6301\u65e5\u671f\u3001\u65f6\u95f4\u3001\u6570\u5b57\u3001\u8d27\u5e01\u7b49\u7684\u683c\u5f0f\u5316\u4e0e\u89e3\u6790\uff0c\u4ee5\u53ca\u4fe1\u606f\u7684\u672c\u5730\u5316\u663e\u793a\u3002<\/li>\n<\/ul>\n<p><p>ICU\u63d0\u4f9b\u7684\u5168\u9762\u529f\u80fd\uff0c\u4f7f\u5176\u6210\u4e3a\u5904\u7406\u56fd\u9645\u5316\u8f6f\u4ef6\u9879\u76ee\u4e2d\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u5904\u7406\u7684\u9996\u9009\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7ed3\u5408\u9009\u62e9<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u54ea\u4e2a\u5b57\u7b26\u5904\u7406\u5e93\uff0c\u53d6\u51b3\u4e8e\u9879\u76ee\u7684\u5177\u4f53\u9700\u6c42\u3002\u5982\u679c\u662f\u7b80\u5355\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c<code>&lt;cstring&gt;<\/code>\u53ef\u80fd\u5c31\u8db3\u591f\u4e86\u3002\u5f53\u9879\u76ee\u9700\u8981\u66f4\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5904\u7406\uff0c\u5982\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u7279\u5b9a\u683c\u5f0f\u5206\u5272\u4e0e\u62fc\u63a5\u65f6\uff0cBoost\u5e93\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\u3002\u800c\u5bf9\u4e8e\u90a3\u4e9b\u9700\u8981\u9ad8\u5ea6\u56fd\u9645\u5316\u652f\u6301\uff0c\u5904\u7406\u591a\u8bed\u8a00\u6587\u672c\u548c\u590d\u6742\u5b57\u7b26\u7f16\u7801\u7684\u9879\u76ee\uff0cICU\u5e93\u5219\u663e\u5f97\u65e0\u53ef\u66ff\u4ee3\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u4ee5\u4e0a\u5e93\u5e76\u975e\u76f8\u4e92\u6392\u65a5\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u7075\u6d3b\u9009\u62e9\u6216\u7ec4\u5408\u8fd9\u4e9b\u5de5\u5177\u5e93\uff0c\u4ee5\u5b9e\u73b0\u6700\u4f18\u7684\u5b57\u7b26\u5904\u7406\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. C\/C++\u4e2d\u662f\u5426\u6709\u4efb\u4f55\u53ef\u4ee5\u5e2e\u52a9\u5904\u7406\u5b57\u7b26\u7684\u5e93\uff1f<\/strong><\/p>\n<p>C\/C++\u662f\u4e00\u79cd\u975e\u5e38\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u62e5\u6709\u8bb8\u591a\u53ef\u4ee5\u5e2e\u52a9\u5904\u7406\u5b57\u7b26\u7684\u5e93\u3002\u4e00\u4e9b\u975e\u5e38\u6d41\u884c\u548c\u597d\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\n<p><strong>Boost String Algorithms\u5e93<\/strong>\uff1a\u8fd9\u4e2a\u5e93\u63d0\u4f9b\u4e86\u8bb8\u591a\u5b57\u7b26\u4e32\u7b97\u6cd5\uff0c\u4f8b\u5982\u67e5\u627e\u3001\u66ff\u6362\u3001\u5206\u5272\u3001\u8f6c\u6362\u5927\u5c0f\u5199\u7b49\u7b49\u3002\u5b83\u53ef\u4ee5\u5927\u5927\u7b80\u5316\u4f60\u5728C\/C++\u4e2d\u5bf9\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u7684\u5de5\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>ICU\uff08International Components for Unicode\uff09\u5e93<\/strong>\uff1a\u8fd9\u4e2a\u5e93\u63d0\u4f9b\u4e86\u5168\u9762\u7684Unicode\u652f\u6301\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5904\u7406\u5404\u79cd\u8bed\u8a00\u548c\u7279\u6b8a\u5b57\u7b26\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528ICU\u5e93\u6765\u8fdb\u884c\u5b57\u7b26\u4e32\u6392\u5e8f\u3001\u5927\u5c0f\u5199\u8f6c\u6362\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>PCRE\uff08Perl Compatible Regular Expressions\uff09\u5e93<\/strong>\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5b57\u7b26\u6a21\u5f0f\u5339\u914d\u5de5\u5177\uff0cPCRE\u5e93\u63d0\u4f9b\u4e86\u4e0ePerl\u517c\u5bb9\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u652f\u6301\u3002\u4f7f\u7528PCRE\u5e93\uff0c\u4f60\u53ef\u4ee5\u5728C\/C++\u4e2d\u8fdb\u884c\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5339\u914d\u548c\u66ff\u6362\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>2. \u54ea\u4e2a\u5b57\u7b26\u5904\u7406\u5e93\u5728C\/C++\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\uff1f<\/strong><\/p>\n<p>\u5728C\/C++\u4e2d\uff0c\u4e00\u4e2a\u975e\u5e38\u5e7f\u6cdb\u4f7f\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\u662f<strong>Standard Template Library (STL)<\/strong>\u3002STL\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u5bb9\u5668\u548c\u7b97\u6cd5\uff0c\u5176\u4e2d\u5305\u62ec\u5bf9\u5b57\u7b26\u4e32\u7684\u5904\u7406\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528STL\u4e2d\u7684string\u7c7b\u6765\u8fdb\u884c\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c\u5982\u62fc\u63a5\u3001\u6bd4\u8f83\u3001\u67e5\u627e\u7b49\u3002\u6b64\u5916\uff0cSTL\u8fd8\u63d0\u4f9b\u4e86\u7b97\u6cd5\u5e93\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u7b97\u6cd5\u6765\u5904\u7406\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\u6392\u5e8f\u3001\u67e5\u627e\u3001\u53bb\u91cd\u7b49\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5b57\u7b26\u5904\u7406\u5e93\uff1f<\/strong><\/p>\n<p>\u9009\u62e9\u5408\u9002\u7684\u5b57\u7b26\u5904\u7406\u5e93\u53d6\u51b3\u4e8e\u4f60\u7684\u5177\u4f53\u9700\u6c42\u548c\u9879\u76ee\u8981\u6c42\u3002\u5982\u679c\u4f60\u9700\u8981\u5904\u7406Unicode\u5b57\u7b26\u6216\u7279\u6b8a\u8bed\u8a00\u5b57\u7b26\uff0cICU\u5e93\u53ef\u80fd\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u590d\u6742\u7684\u6a21\u5f0f\u5339\u914d\u548c\u66ff\u6362\u64cd\u4f5c\uff0c\u4f7f\u7528PCRE\u5e93\u53ef\u80fd\u66f4\u9002\u5408\u4f60\u3002\u800c\u5982\u679c\u4f60\u53ea\u662f\u9700\u8981\u8fdb\u884c\u57fa\u672c\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0cSTL\u7684string\u7c7b\u53ef\u80fd\u5df2\u7ecf\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\u3002\u5728\u9009\u62e9\u5b57\u7b26\u5904\u7406\u5e93\u4e4b\u524d\uff0c\u5efa\u8bae\u5148\u4ed4\u7ec6\u5206\u6790\u4f60\u7684\u9700\u6c42\uff0c\u5e76\u5bf9\u4e0d\u540c\u7684\u5e93\u8fdb\u884c\u8bc4\u4f30\u548c\u6bd4\u8f83\uff0c\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u5e93\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728C\/C++\u4e2d\uff0c\u6709\u591a\u79cd\u975e\u5e38\u597d\u7528\u7684\u5b57\u7b26\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u7b80\u5316\u548c\u52a0\u901f\u5f00\u53d1\u8fc7\u7a0b\u3002\u8fd9\u4e9b\u5e93\u5305\u62ec\u6807\u51c6\u5e93 &lt;cstri [&hellip;]","protected":false},"author":3,"featured_media":301313,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/301293"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=301293"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/301293\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/301313"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=301293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=301293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=301293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}