当前位置: 首页 > news >正文

南昌做企业网站百度快速排名培训

南昌做企业网站,百度快速排名培训,怎么做网站移植网站,怎么套模板 网站代码在GitHubMaolinYe/CodeCounter: C20实现的代码统计器,代码量小于100行,可以统计目录下所有代码文件的行数 (github.com) 前段时间到处面试找实习,有技术负责人的负责人问我C写过多少行,5万还是10万,用来评估熟练度…

代码在GitHubMaolinYe/CodeCounter: C++20实现的代码统计器,代码量小于100行,可以统计目录下所有代码文件的行数 (github.com)

前段时间到处面试找实习,有技术负责人的负责人问我C++写过多少行,5万还是10万,用来评估熟练度,有点难顶,于是写个代码统计器吧,输入文件夹目录或者代码文件,可以统计所有代码的行数

可以直接编译代码运行程序,在控制台输入目录的路径按下回车即可,例如输入

C:\Users\Yezi\Desktop\C++\CodeCounter

也可以在终端命令行直接运行编译好的程序,带上参数运行,例如输入

.\CodeCounter.exe C:\Users\Yezi\Desktop\C++\CodeCounter

思路比较简单,主要是用到了C++17的filesystem库用来解析目录和提取文件后缀,如果路径是个目录就提取子目录项逐个分析,如果子目录项是目录就递归调用本身继续解析目录,如果是代码文件就开始计数行数

//
// Created by YEZI on 2024/5/20.
//#ifndef CODECOUNTER_H
#define CODECOUNTER_H
#include<vector>
#include<string>
#include<filesystem>
#include <fstream>
#include <iostream>class CodeCounter {int lines = 0;// 检查是否是代码文件static bool isCodeFile(const std::filesystem::path &path) {// 常见代码文件后缀static const std::vector<std::string> extensions = {".cpp", ".h", ".java", ".py", ".cs", ".js", ".go", ".c", ".cc", ".hh"};// 检查路径是否存在if (std::filesystem::exists(path) == false) {std::cerr << "There is no file " << path << std::endl;return false;}// 检查是否是文件if (is_regular_file(path) == false) {std::cerr << path << " is no a file." << std::endl;return false;}std::string extension = path.extension().string();for (const auto &e: extensions) {if (e == extension) {return true;}}return false;}void countCodeFile(const std::filesystem::path &filePath) {// 检查是否是代码文件if (isCodeFile(filePath) == false)return;std::ifstream file(filePath);// 检查文件是否可以打开if (file.is_open() == false) {std::cerr << "Error opening file: " << filePath << std::endl;return;}std::string trash;int count=0;while (std::getline(file, trash)) {++count;}lines+=count;std::cout<<filePath<<" Lines: "<<count<<std::endl;}void countDirectory(const std::filesystem::path &path) {// 检查是否是目录if (is_directory(path) == false)return;for (const auto &entry: std::filesystem::directory_iterator(path)) {if (entry.is_directory())countDirectory(entry.path());elsecountCodeFile(entry.path());}}public:void countThis(const std::filesystem::path &path) {if (is_directory(path))countDirectory(path);elsecountCodeFile(path);std::cout << "Code Lines: " << lines;}
};
#endif //CODECOUNTER_H

从命令行参数读取目录或者从控制台输入读取目录

#include <iostream>
#include"CodeCounter.h"int main(int argc, char *argv[]) {CodeCounter code_counter;std::string path;if (argc == 2)path.assign(argv[1]);elsestd::getline(std::cin, path);code_counter.countThis(path);return 0;
}
http://www.hrbkazy.com/news/35811.html

相关文章:

  • 网站建设的原则北京搜索引擎优化主管
  • 遵义市乡村街道建设投诉网站深圳今天重大事件新闻
  • 美丽寮步网站建设宁波网站快速优化
  • 做教育app的网站有哪些内容网络营销渠道可分为
  • 专业做企业网站无锡百度推广代理商
  • 做站群网站好优化吗站点推广是什么意思
  • 章丘建设局网站seo入门培训
  • 网站是怎么做新手引导优化网站推广网站
  • 不懂代码可以做网站吗app推广在哪里可以接单
  • 哈尔滨网站优化咨询公司网络优化方案
  • 织梦php网站友情链接交易平台
  • 网站互联网设计图风格seo快速排名上首页
  • 网上做博彩网站代理三十个知识点带你学党章
  • 个人网站 建设2021年经典营销案例
  • 河北 建设厅网站首页优化关键词方法
  • 前程无忧做一年网站多钱浙江网站建设平台
  • 南京教育网站开发cps推广
  • 二合一收款码免费制作网站百度官网首页入口
  • 家政行业网站建设方案seo搜索引擎优化内容
  • 国外的服务器建设的网站在线网页制作网站
  • 网投网站制作推广搜索怎么选关键词
  • flash个人网站动画网络营销教学大纲
  • 太原网页制作招聘网运营seo是什么意思
  • 网站及app建设windows优化大师可以卸载吗
  • 幼儿园网站制作代码下载安装百度一下
  • 网站域名正在维护中新闻今日要闻
  • 营销型网站建设教学网站后台管理系统
  • 湛江做网站从网站整站优化公司
  • 阿里云服务器 多个网站搜索引擎排名google
  • 网站定制微安电力案例模板免费下载网站