{"id":505,"date":"2020-05-04T01:15:58","date_gmt":"2020-05-03T17:15:58","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=505"},"modified":"2020-05-04T01:15:58","modified_gmt":"2020-05-03T17:15:58","slug":"%e8%ae%a1%e7%ae%97%e9%a1%b9%e7%9b%ae%e7%9a%84%e4%bb%a3%e7%a0%81%e6%80%bb%e8%a1%8c%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=505","title":{"rendered":"\u4f18\u96c5\u5730\u7edf\u8ba1\u4ee3\u7801\u603b\u884c\u6570"},"content":{"rendered":"<h3>\u5f15\u8a00<\/h3>\n<p>\u5f53\u9879\u76ee\u6587\u4ef6\u6bd4\u8f83\u591a\u65f6\uff0c\u7edf\u8ba1\u4ee3\u7801\u91cf\u53d8\u6210\u4e00\u4e2a\u5f88\u9ebb\u70e6\u7684\u4e8b\u60c5\u3002<br \/>\n\u201c\u6253\u5f00Python\u624b\u52a8\u8ba1\u7b97\u5427\u3002\u201d<br \/>\n\u201c\u6b63\u7ecf\u4eba\u8c01\u8ba1\u7b97\u554a\u3002\u201d<br \/>\n\u201c\u662f\u554a\u3002\u201d<br \/>\n\u201c\u4f60\u8ba1\u7b97\u5417\uff1f\u201d<br \/>\n\u201c\u6211\u4e0d\u8ba1\u7b97\u3002\u201d<br \/>\n\u201c\u8c01\u6709\u65f6\u95f4\u4e00\u4e2a\u4e00\u4e2a\u7684\u7b97\uff1f\u201d<br \/>\n\u201c\u4e0b\u8d31\u3002\u201d<br \/>\n\u201c\u4e0b\u8d31\u3002\u201d<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.guanhaobo.cn\/wp-content\/uploads\/2020\/05\/1001.jpg\" alt=\"\" \/><\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<p>\u601d\u8def\uff1a\u5bf9\u4e8e\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u83b7\u53d6\u91cc\u9762\u6240\u6709\u6587\u4ef6\u7684\u8def\u5f84\uff08\u5305\u62ec\u5b50\u6587\u4ef6\u5939\u91cc\u7684\u6587\u4ef6\uff09\uff0c\u5224\u65ad\u6587\u4ef6\u6269\u5c55\u540d\u662f\u5426\u662f\u76ee\u6807\u6269\u5c55\u540d\uff0c\u5982\u679c\u662f\u5219\u8bfb\u53d6\u6587\u4ef6\u7684\u884c\u6570\u3002<\/p>\n<h4>C++\u4ee3\u7801<\/h4>\n<p>\u6700\u65b0\u7248\u8bf7\u8bbf\u95ee<a href=\"https:\/\/github.com\/ghb123\/CodeCounter\">https:\/\/github.com\/ghb123\/CodeCounter<\/a><\/p>\n<pre><code class=\"language-cpp line-numbers\">\/\/www.guanhaobo.cn\n#include &lt;io.h&gt;\n#include &lt;vector&gt;\n#include &lt;string&gt;\n#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\nvector&lt;string&gt; files; \/\/\u5b58\u50a8\u6587\u4ef6\u8def\u5f84\nvector&lt;string&gt; type;  \/\/\u6307\u5b9a\u6269\u5c55\u540d\n\n\/\/\u83b7\u53d6\u8def\u5f84path\u4e0b\u6240\u6709\u7684\u6587\u4ef6\u540d\uff08\u5305\u62ec\u5b50\u6587\u4ef6\u5939\u91cc\u7684\uff09\uff0c\u5b58\u50a8\u5728files\u4e2d\nvoid getFiles(string path, vector&lt;string&gt; &amp;files)\n{\n    \/\/\u6587\u4ef6\u53e5\u67c4\n    long hFile = 0;\n    \/\/\u6587\u4ef6\u4fe1\u606f\n    struct _finddata_t fileinfo;\n    string p;\n    if ((hFile = _findfirst(p.assign(path).append(\"\\\\*\").c_str(), &amp;fileinfo)) != -1)\n    {\n        do\n        { \/\/\u5982\u679c\u662f\u76ee\u5f55,\u8fed\u4ee3\u4e4b\n            \/\/\u5982\u679c\u4e0d\u662f,\u52a0\u5165\u5217\u8868\n            if ((fileinfo.attrib &amp; _A_SUBDIR))\n            {\n                if (strcmp(fileinfo.name, \".\") != 0 &amp;&amp; strcmp(fileinfo.name, \"..\") != 0)\n                    getFiles(p.assign(path).append(\"\\\\\").append(fileinfo.name), files);\n            }\n            else\n                files.push_back(p.assign(path).append(\"\\\\\").append(fileinfo.name));\n        } while (_findnext(hFile, &amp;fileinfo) == 0);\n        _findclose(hFile);\n    }\n}\n\n\/\/\u83b7\u53d6\u6587\u4ef6\u884c\u6570\nint getLineNum(string path)\n{\n    int ans = 0, first = 1;\n    char ch = ' ';\n    FILE *fp = fopen(path.c_str(), \"r\");\n    if (fp == NULL)\n        return 0;\n    while (ch != EOF)\n    {\n        ch = fgetc(fp);\n        if (ch == '\\n')\n            ans++;\n    }\n    return ans + 1;\n}\n\n\/\/\u5224\u65ad\u662f\u5426\u662f\u76ee\u6807\u6269\u5c55\u540d\nbool isTarget(string path)\n{\n    if (type.size() == 0)\n        return true;\n    string name = path.substr(path.find_last_of(\".\") + 1);\n    if (find(type.begin(), type.end(), name) != type.end())\n        return true;\n    return false;\n}\n\nint main()\n{\n    string filePath;\n    cout &lt;&lt; \"\u8bf7\u8f93\u5165\u9879\u76ee\u6587\u4ef6\u5939\u7684\u8def\u5f84\uff1a\";\n    cin &gt;&gt; filePath;\n    \/\/\u8bbe\u7f6e\u6269\u5c55\u540d\n    type.push_back(\"java\");\n    \/\/\u8bfb\u53d6\u6240\u6709\u6587\u4ef6\u7684\u8def\u5f84\n    getFiles(filePath, files);\n    int num, ans = 0;\n    for (int i = 0; i &lt; files.size(); i++)\n    {\n        \/\/\u5982\u679c\u662f\u76ee\u6807\u6269\u5c55\u540d\uff0c\u5219\u8bfb\u53d6\u884c\u6570\n        if (isTarget(files[i]))\n        {\n            num = getLineNum(files[i]);\n            ans += num;\n            cout &lt;&lt; files[i] &lt;&lt; \"    \u884c\u6570\uff1a\" &lt;&lt; num &lt;&lt; endl;\n        }\n    }\n    cout &lt;&lt; endl\n         &lt;&lt; \"\u603b\u884c\u6570\uff1a\" &lt;&lt; ans &lt;&lt; endl;\n    return 0;\n}\n<\/code><\/pre>\n<h4>\u600e\u4e48\u4fee\u6539\u4e0a\u9762\u7684\u4ee3\u7801<\/h4>\n<p>type\u7528\u6765\u5b58\u50a8\u6269\u5c55\u540d\uff0c\u53ea\u8981\u5728main\u51fd\u6570\u91cc\u5c06\u6240\u6709\u60f3\u8981\u7684\u6269\u5c55\u540d\u6dfb\u52a0\u8fdbtype\u91cc\u5373\u53ef\u3002<\/p>\n<pre><code class=\"language-cpp line-numbers\">\/\/\u8bbe\u7f6e\u6269\u5c55\u540d\ntype.push_back(\"java\");\ntype.push_back(\"xml\");\ntype.push_back(\"cpp\");\n\/\/\u8bfb\u53d6\u6240\u6709\u6587\u4ef6\u7684\u8def\u5f84\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u60f3\u9650\u5236\u6269\u5c55\u540d\uff0c\u5219\u4e0d\u8981\u5411type\u91cc\u6dfb\u52a0\u4efb\u4f55\u4e1c\u897f\u3002<\/p>\n<pre><code class=\"language-cpp line-numbers\">\/\/\u8bbe\u7f6e\u6269\u5c55\u540d\n\/\/\u8bfb\u53d6\u6240\u6709\u6587\u4ef6\u7684\u8def\u5f84\n<\/code><\/pre>\n<h4>\u8fd0\u884c\u6d4b\u8bd5<\/h4>\n<p>\u8f93\u5165\u9879\u76ee\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.guanhaobo.cn\/wp-content\/uploads\/2020\/05\/1002.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"http:\/\/www.guanhaobo.cn\/wp-content\/uploads\/2020\/05\/1003.jpg\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u5f53\u9879\u76ee\u6587\u4ef6\u6bd4\u8f83\u591a\u65f6\uff0c\u7edf\u8ba1\u4ee3\u7801\u91cf\u53d8\u6210\u4e00\u4e2a\u5f88\u9ebb\u70e6\u7684\u4e8b\u60c5\u3002 \u201c\u6253\u5f00Python\u624b\u52a8\u8ba1\u7b97\u5427\u3002\u201d \u201c\u6b63\u7ecf\u4eba\u8c01\u8ba1\u7b97\u554a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[8],"class_list":["post-505","post","type-post","status-publish","format-standard","hentry","category-note","tag-cpp"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=505"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/505\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}