项目代码行数统计/软著源代码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& 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 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 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;
}

如果您觉得这篇博文有用,请访问我的个人站:http://www.stubbornhuang.com/,更多博文干货等着您。

你可能感兴趣的:(C++,其它)