当前位置: 首页 > news >正文

c++生成html文件helloworld

说明:
c++生成html文件helloworld
效果图:
在这里插入图片描述

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

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

#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:运行

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

相关文章:

  • 免费做名片儿的网站黄冈seo
  • 中国教学网站十大最免费软件排行榜
  • wordpress建站属于前端最佳磁力搜索天堂
  • 下载wordpress 5.2.2青岛seo排名扣费
  • 2022年互联网营销师如何报名重庆seo网络推广关键词
  • 多种专业网站建设天津百度推广中心
  • 智能体开发平台与大模型关系图谱
  • 经典论文解读系列:MapReduce 论文精读总结:简化大规模集群上的数据处理
  • SpringBoot条件装配注解
  • 网络原理-TCP/IP
  • rviz可视化(一、可视化点云)
  • 4. Flink SQL访问HiveCatalog
  • <em>凤</em><em>凰</em><em>购</em><em>彩</em><em>大</em><em>厅</em>
  • 三个核心文件:src\App.vue文件,index.html文件,src\main.js文件 的关系与运行流程解析(通俗形象)
  • L2-037 包装机 (分数25)(详解)
  • DeepSeek协助优化-GTX750Ti文物显卡0.65秒卷完400MB float 音频512阶时域FIR
  • OTN(Optical Transport Network)详解
  • RK3588,V4l2 读取Gmsl相机, Rga yuv422转换rgb (dma), 实现零拷贝
  • 【Deep Reinforcement Learning Hands-On Third Edition】【序】
  • Python Django基于人脸识别的票务管理系统(附源码,文档说明)
  • 运算放大器(三)运算放大器的典型应用
  • Zoomlt使用
  • 解决:在运行 plt.show()`时,程序会等待你手动关闭图片窗口才能继续往下执行
  • 基于YOLO11/WVP的电梯系统开发-模型训练与rk3568移植
  • HarmonyOS NEXT——【鸿蒙实现录音识别(语音转文字)】
  • Node.js 技术原理分析系列 —— Node.js 调试能力分析