Java程序员两三千行代码_项目代码行数统计/软著源代码3000行代码生成

#include

#include

#include

#include

#include

using namespace std;

void split(const string& str, const string& sp, vector& vec)

{

size_t size = sp.size();

vec.clear();

size_t end = 0, start = 0;

while (start != string::npos && start < str.size())

{

end = str.find(sp, start);

vec.push_back(str.substr(start, end - start));

start = end == string::npos ? end : end + size;

}

if (vec.empty())

vec.push_back(str);

}

void GetSpecialFilesFromDirectory(string path, string fileType, vector& files)

{

vector tempFileTypes;

split(fileType, " ", tempFileTypes);

if (tempFileTypes.size() == 0)

return;

for (int i=0;i

{

// 文件句柄

long hFile = 0;

// 文件信息

struct _finddata_t fileinfo;

string p;

if ((hFile = _findfirst(p.assign(path).append("\\*" + tempFileTypes[i]).c_str(), &fileinfo)) != -1) {

do

{

// 第一种:保存文件的全路径

files.push_back(p.assign(path).append("\\").append(fileinfo.name));

//第二种:不保存文件的全路径

//files.push_back(fileinfo.name);

} while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1

_findclose(hFile);

}

}

}

void GetAllFilesIncludeSubfolder(string path,string fileType,vector& files)

{

vector tempFileTypes;

split(fileType, " ", tempFileTypes);

if (tempFileTypes.size() == 0)

return;

//文件句柄

long hFile = 0;

//文件信息

struct _finddata_t fileinfo;

string p;

if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)

{

do

{

if ((fileinfo.attrib & _A_SUBDIR))

{ //比较文件类型是否是文件夹

if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)

{

string subForld = p.assign(path).append("\\").append(fileinfo.name);

//递归搜索

GetSpecialFilesFromDirectory(subForld, fileType, files);

GetAllFilesIncludeSubfolder(p.assign(path).append("\\").append(fileinfo.name),fileType, files);

}

}

else

{

for (int i=0;i

{

string fileName = fileinfo.name;

if (fileName.find(tempFileTypes[i]) != std::string::npos)

{

// 第一种:保存文件的全路径

files.push_back(p.assign(path).append("\\").append(fileinfo.name));

//第二种:不保存文件的全路径

//files.push_back(fileinfo.name);

}

else

{

continue;

}

}

}

} while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1

_findclose(hFile);

}

}

std::string GetFileContent(const std::string& filepath)

{

std::ifstream infile;

infile.open(filepath);

std::string fileContent = "";

if (infile.is_open())

{

std::string tempString;

while (getline(infile, tempString))

{

fileContent += tempString;

}

infile.close();

}

else

{

std::cout << "Fail to open the config file:" << filepath << std::endl;

}

return fileContent;

}

int main()

{

int codeLineCount = 0;

vector m_Files;

string path = "E:\\test\\src";

GetAllFilesIncludeSubfolder(path, ".h .cpp", m_Files);//这里以空格分割文件后缀名

ofstream outputFile;

outputFile.open("C:\\Users\\Administrator\\Desktop\\CodeContent.txt",ios::out);

for (int i=0;i

{

std::ifstream infile;

infile.open(m_Files[i]);

if (infile.is_open())

{

std::string tempString;

while (getline(infile, tempString))

{

//软著只需要3000行代码

/*if (codeLineCount > 3000)

{

break;

}*/

if(tempString.find("//")!= string::npos || tempString.find("/*") != string::npos)

{

cout << "注释" << endl;

continue;

}

else if(tempString.length() == 0)

{

cout << "空行" << endl;

continue;

}

else

{

outputFile << tempString << endl;

codeLineCount++;

}

}

infile.close();

}

else

{

std::cout << "Fail to open the config file:" << m_Files[i] << std::endl;

}

}

outputFile.flush();

outputFile.close();

cout << "项目代码总行数 = " << codeLineCount << endl;

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值