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

相关推荐
程与留6 分钟前
09_Qt 布局管理系统——QHBoxLayout、QVBoxLayout、QGridLayout
c++·qt
神仙别闹9 分钟前
基于QT(C++)实现旅游线路规划系统
c++·qt·旅游
2601_9669496510 分钟前
Python 量化数据质量校验:如何确保股票历史日线数据不存在缺失交易日?
开发语言·人工智能·爬虫·python·量化策略·量化·quantdash
广东帝工智能安防17 分钟前
BCAS桥梁防撞预警系统五层架构深度解析:从感知层到对接层的技术实现与选型指南
开发语言·人工智能·架构·边缘计算·桥梁防撞预警系统
树码小子21 分钟前
Skill的格式 & 开发语言和工具
开发语言·skill
Java后端的Ai之路23 分钟前
05、Python单例模式完全指南
开发语言·人工智能·python·单例模式·oracle
郝学胜_神的一滴23 分钟前
C++11 工程级应用 02:decltype与返回类型后置,让泛型代码告别类型玄学
c++·编程语言
≮傷£≯√23 分钟前
音量调节弹窗 自定义组件qt
开发语言·qt
多弗朗皮卡丘32 分钟前
C语言梦开始的地方16:结构体
c语言·开发语言·windows
tudousisi2221 小时前
8.25第二题训练
c++