用于生成html超鏈接方便下載
#include<Windows.h>
#include<iostream>
#include<io.h>
#include<string>
#include<vector>
using namespace std;
size_t FinFiles(vector<string>&files)
{
files.clear();
char buffer[MAX_PATH] = {};
GetCurrentDirectoryA(MAX_PATH, buffer);
string path = buffer;
path += "\\*.*";
_finddata_t fileinfo;
long handle = _findfirst(path.c_str(), &fileinfo);
if (handle == -1)
{
return -1;
}
do
{
printf("%s\n", fileinfo.name);
files.push_back(fileinfo.name);
} while (!_findnext(handle, &fileinfo));
_findclose(handle);
handle = 0;
return files.size();
}
bool MakeHtml(vector<string>&files)
{
FILE* pfile;
fopen_s(&pfile, "test", "wb+");
if (pfile == nullptr)
{
return false;
}
string s1 = "<a href=https://www.cnblogs.com/"";
string s2 = "/">";
string s3 = "
/n";
for each(string curfile in files)
{
string s = s1 + curfile + s2 + curfile + s3;
cout << s << endl;
fwrite(s.c_str(), 1, s.length(), pfile);
}
fclose(pfile);
pfile = 0;
return true;
}
int main()
{
vectorfiles;
FinFiles(files);
MakeHtml(files);
system("pause");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/3615.html
標籤:C++
上一篇:Hello,World!
下一篇:C++基本語法
