c++生成html文件helloworld

说明:

c++生成html文件helloworld

效果图:

step1:C:\Users\wangrusheng\CLionProjects\untitled15\CMakeLists.txt

bash 复制代码
cmake_minimum_required(VERSION 3.30)
project(untitled15)

set(CMAKE_CXX_STANDARD 20)

add_executable(untitled15 main.cpp)

# 添加filesystem库支持
target_link_libraries(untitled15 PRIVATE stdc++fs)

step2:C:\Users\wangrusheng\CLionProjects\untitled15\main.cpp

c 复制代码
#include <iostream>
#include <fstream>
#include <filesystem>

int main() {
    // Create HTML content
    const char* html_content = R"(
<!DOCTYPE html>
<html>
<head>
    <title>C++ Generated HTML</title>
</head>
<body>
    <h1>Hello World from C++!</h1>
    <p>This file was generated by a C++ program.</p>
</body>
</html>
)";

    // Set filename and path
    const std::string filename = "generated_page.html";
    std::ofstream outfile(filename);

    if (outfile) {
        // Write content to file
        outfile << html_content;
        outfile.close();

        // Get and display full path
        namespace fs = std::filesystem;
        std::cout << "HTML file created at:\n"
                  << fs::absolute(filename) << std::endl;
    } else {
        std::cerr << "Failed to create file!" << std::endl;
        return 1;
    }

    return 0;
}

step3:运行

bash 复制代码
C:\Users\wangrusheng\CLionProjects\untitled15\cmake-build-debug\untitled15.exe
HTML file created at:
"C:\\Users\\wangrusheng\\CLionProjects\\untitled15\\cmake-build-debug\\generated_page.html"

Process finished with exit code 0

end

相关推荐
山楂树の38 分钟前
Python Pandas 数据处理:数据读取、筛选、清洗、排序与分组
开发语言·python·pandas
汉克老师1 小时前
GESP六级第二课:森林里的分叉城堡——二叉树的构造与存储
c++·二叉树·树·gesp·小学生·小学生学编程
xurileidian2 小时前
第 22 篇 · 边玩边学Python · 双等号与 is 不是一回事
开发语言·python·spring
FRing032 小时前
for循环、while循环、Java高级语法、数组
java·开发语言·后端·算法
syf0611132 小时前
Java Math 类详解:常用数学运算方法全解析
java·开发语言
老歌老听老掉牙2 小时前
三个等价答案:遗传算法如何逼近 Branin 函数
c++·算法·ga
是main不是漫2 小时前
【双指针 | LeetCode11 盛最多水的容器】O(n²) 超时,O(n) 封神:这道“装水题“只差一个思路
开发语言·数据结构·c++·算法
慧都产品智能化3 小时前
汽车软件年底自查:按安全影响排定缺陷整改顺序
c语言·c++·测试工具·单元测试·汽车·代码规范
geovindu3 小时前
python: Gradient Boosting
开发语言·后端·python·算法·boosting
星夜离尘564 小时前
MATLAB:两路读数平均相差 8 mV,换位能分出传感器偏差和通道偏差吗?
开发语言·matlab