嗨,我正在编写一个程序,它打开一个目录,读取所有 zip 文件并解压缩它们,然后我想创建一个 html 文件并在新的 html 文件中显示解压缩文件夹中的所有图片。我读过使用 ofstream 是一个好主意,我一直在尝试……但我无法显示图片。
这是我到目前为止写的代码
我真的很想知道如何显示图片以使其正常工作,尤其是这部分 --- myfile<<" ";
谢谢
// HTML部分
std::ifstream fin_html;
std::string dir_html, filepath_html;
int num;
DIR *dp_html;
struct dirent *dirp_html;
dir_html = dir + "/" + "ExtractedZipFiles";
dp_html = opendir( dir_html.c_str() );
if (dp_html == NULL)
{
std::cout << "Error opening " << dir_html << std::endl;
}
char test_html[2];
std::ofstream myfile;
std::string htmlFile= dir + "/" +"Images";
myfile.open (htmlFile.c_str());
myfile<<"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN \" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \">";
myfile<<"<html xmlns=\"http://www.w3.org/1999/xhtml\" >";
myfile<<"<head>";
std::string title="Sample Data";
myfile<<"<title>"<<title<<"</title>";
myfile<<"</head>";
myfile<<"<body>";
myfile<<"<br />";
myfile<<"<HR />";
myfile<<"beta data ";
while ((dirp_html = readdir( dp_html )) != NULL)
{ // printf(" inside the directory ");
filepath = dir+"/" + dirp_html->d_name;
filename =dirp_html->d_name;
std::cout<<filename;
myfile<<"<p>";
myfile<<"<a href=filepath>"<<filename<<"</a>";
myfile<<"</p>";
std::cout<<std::endl;
std::cout<<filepath;
std::cout<<std::endl;
test[0]=filename[0];
test[1]='\0';
std::string dir_htmlArray[12];
//dp_html=opendir(dir_html.c_str());
for (int i=0;i<=11;i++)
{
dir_htmlArray[i]= "ExtractedZipFiles"+filename+nameArray[i];
}
myfile<<"<a href=dir_htmlArray1> <img src=dir_htmlArray1 width=24% border=0/> </a>"; //rtyin
}
// return 0;
myfile<<"</body></html>";
myfile.close();
}