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

相关推荐
蜗牛love天空几秒前
qt窗口机制和mfc窗口机制
c++
编织幻境的妖1 分钟前
Python对象序列化和反序列化方法总结
开发语言·python
BUG创建者2 分钟前
thee.js完成线上展厅demo
开发语言·前端·javascript·css·html·css3·three.js
Cherry的跨界思维3 分钟前
8、Python正则表达式精准搜索实战:从模糊匹配到精准定位
开发语言·python·正则表达式·django·flask·pygame·tornado
星释4 分钟前
Rust 练习册 113:构建你自己的 CSV 处理器
开发语言·windows·rust
定义小花6 分钟前
c++ cmake qt
开发语言·c++·qt
软件开发技术深度爱好者7 分钟前
Python + Ursina设计3D小游戏
开发语言·python
黑客思维者7 分钟前
Python 3.14(2025最新版)的核心语法特性分析
服务器·开发语言·python·多线程
蚊子爱喝水7 分钟前
PHP/ThinkPHP 最佳实践:DeepSeek/OpenAI API 实时流式输出 (Streaming) 完整指南
开发语言·php
草莓熊Lotso8 分钟前
哈希表的两种灵魂:深入探索开放定址与链地址法的核心机密
linux·运维·数据结构·c++·人工智能·算法·哈希算法