#include <string>
#include <fstream>
#include <stdlib.h>
这是头文件
using namespace std;
使用命名空间
char code[10][100] = {
"<!DOCTYPE html>",
"html",
"head",
"<title>我的HTML程序</title>",
"/haed",
"<h1>标题</h1>",
"<p>段落</p>",
"</body>",
"</html>",
};
数组初始化
ofstream outfile("website.html");
for (int i = 0; i < 10; i++) {
outfile << code[i] << '\n';
}
outfile.close();
system("start website.html");
打开HTML窗口
以下是完整代码:
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main() {
char code[10][100] = {
"<!DOCTYPE html>",
"html",
"head",
"<title>我的HTML程序</title>",
"/haed",
"<h1>标题</h1>",
"<p>段落</p>",
"</body>",
"</html>",
};
ofstream outfile("website.html");
for (int i = 0; i < 10; i++) {
outfile << code[i] << '\n';
}
outfile.close();
system("start website.html");
return 0;
}