如何用c++生成html5文件并进行编程

本文介绍如何在C++项目中,使用VisualStudio2013/2015环境生成并编程.htm或.html文件,包括建立文件、设置属性、编写HTML代码及循环填充表格的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候根据项目需要,在一个c++项目里面,需要对某些结果保存为.htm或者.html文件,并根据需要,在visual studio2013/2015的c++环境下对该.html文件进行编程。这样做,一方面为了输出结果需要,一方面便于浏览器打开。

首先

建立3个.html文件,并设置好属性:

ofstream totalHtml,passHtml,failHtml;
totalHtml.open(imgsSavePath + "/total.html", ios::out | ios::trunc);// 文件若不存在,就新建;若存在,则覆盖
passHtml.open(imgsSavePath + "/pass.html", ios::out | ios::trunc);
failHtml.open(imgsSavePath + "/fail.html", ios::out | ios::trunc);
然后

往3个.html文件里面写入html程序,这里要注意:
1、所有的html程序全部在“”里面;
2、如果html程序里面需要用到“,此时注意转义字符“\”的使用。

//pass.html和fail.html文件头处理及相关类的样式定义
	passHtml << "<head>";
	passHtml << "<meta http-equiv=\"Content-type\" content=\"text/css;charset=utf-8\"/>";
	passHtml << "<title>Pass-Components</title>";
	passHtml << "<style type=\"text/css\" media=\"screen\">";
	passHtml << "body{font-family:Arial;font-size:small;text-align:Center;color:Black;background:White;}";
	passHtml << "table{margin-left:auto;margin-right:auto;text-align:center;}";
	passHtml << ".step_row_pass{text-align:center;background-color:rgb(0,255,0);vertical-align:middle;border:Black;padding:1%;}";
	passHtml << "</style></head>";
	passHtml << "<h3 style = \"background-color:rgb(0,255,0);text-align:center\">Passed Components List</h3>";
	passHtml << "<table width=\"50%\"><tbody>";

	failHtml << "<head>";
	failHtml << "<meta http-equiv=\"Content-type\" content=\"text/css;charset=utf-8\"/>";
	failHtml << "<title>Fail-Components</title>";
	failHtml << "<style type=\"text/css\" media=\"screen\">";
	failHtml << "body{font-family:Arial;font-size:small;text-align:Center;color:Black;background:White;}";
	failHtml << "table{margin-left:auto;margin-right:auto;text-align:center;}";
	failHtml << ".step_row_fail{text-align:center;color:black;background-color:rgb(255,128,128);vertical-align:middle;border:Silver;padding:1%;}";
	failHtml << "</style></head>";
	failHtml << "<h3 style =\"background-color:rgb(255,128,128);text-align:center\">Fault Components List</h3>";
	failHtml << "<table width=\"50%\"><tbody>";
再然后

就是对3个.html文件的“table”进行一行行增加,这里我用的是while循环:

	while (mImagesListRead.good() && !mImagesListRead.eof())  //循环读取图像序列
	{
	...
		failHtml << "<tr><td width=\"10%\" class=\"step_row_fail\">" << mImageId << "</td>";
		failHtml<<"<td width=\"10%\" class=\"step_row_fail\">fault</td>";
		failHtml << "<td class=\"step_row_fail\"><img src=\"./FaultImgs/"<< mImageId << ".png\"/> </td></tr>";
		faultnum++;
		...
	}
最后注意收尾
totalHtml << "<title>Result</title>";
totalHtml << "<h3 style=\"background-color:gray;color:blue;text-align:center\">Analysis Results</h3><hr/>";
totalHtml << "<p width=\"50%\" style=\"background-color:yellow;text-align:center\">Components Number: " << mImagesCount << "</p><hr/>";
totalHtml << "<base target=\"_blank\" /> <p style = \"background-color:rgb(0,255,0);text-align:center\">";
totalHtml<<"<a href =\"pass.html\"><b>Pass</b>-Components</a>:  " << mImagesCount - faultnum << "</p><hr/>";
totalHtml << "<p style =\"background-color:rgb(255,128,128);text-align:center\">";
totalHtml<<"<a href =\"fail.html\"><b>Fail</b>-Components</a>:  " << faultnum << "</p>";
totalHtml.close();

passHtml << "</tbody></table>";
passHtml.close();

failHtml << "</tbody></table>";
failHtml.close();
html5c++开源 K线图工具, Create interactive charts easily for your web projects. Used by tens of thousands of developers and 61 out of the world's 100 largest companies, Highcharts is the simplest yet most flexible charting API on the market. Read more » Download » TemperatureRainfallTokyo climateSunshine hoursJanFebMarAprMayJunJulAugSepOctNovDec5°C10°C15°C20°C25°C30°C0 mm50 mm100 mm150 mm200 mm250 mmHighcharts.com Highstock Highstock lets you create stock or general timeline charts in pure JavaScript. Including sophisticated navigation options like a small navigator series, preset date ranges, date picker, scrolling and panning. Read more » Download » ZoomUSD to EUR14. Feb21. Feb28. Feb7. Mar14. Mar21. Mar28. Mar4. Apr11. Apr18. Apr25. Apr2. May9. May20042006200820100.70.650.751m3m6mYTD1yAllHighcharts.com Highmaps Interactive map charts with drilldown and touch support. Build interactive maps to display sales, election results or any other information linked to geography. Perfect for standalone use or in dashboards in combination with Highcharts! Read more » Download » Highcharts © Natural Earth Highcharts Cloud Online charts for non-techies. Create smashing, interactive diagrams for your news site or blog, or for sharing with your friends on social media. Read more » Highcharts Cloud 1 2 3 4 Free for non-commercial Do you want to use Highcharts for a personal website, a school site or a non-profit organisation? Then you don't need our permission, just go on! HTML 5 Based on native browser technologies, no plugins needed Open Fork us on GitHub and participate in tech discussions Compatible With modern browsers including mobile, tablets and old IE back to IE6 Dynamic Add, remove and modify series and points or modify axes Any chart you'd like Highcharts supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerang
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值