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

相关推荐
try again!2 分钟前
rollup.js 和 webpack
开发语言·javascript·webpack
前端Hardy9 分钟前
HTML&CSS:超好看的轮播图,你绝对用得上(建议收藏)
javascript·css·html
du fei13 分钟前
C# 窗体应用(.FET Framework) 线程操作方法
开发语言·c#
du fei15 分钟前
C#文件操作
开发语言·c#
前端Hardy16 分钟前
HTML&CSS:必学!手把手教你实现动态天气图标
javascript·css·html
m0_5557629024 分钟前
struct 中在c++ 和c中用法区别
java·c语言·c++
月亮有痕迹诶27 分钟前
【C++】智能指针
开发语言·c++·c++11
搞不懂语言的程序员33 分钟前
装饰器模式详解
开发语言·python·装饰器模式
王禄DUT37 分钟前
化学方程式配平 第33次CCF-CSP计算机软件能力认证
开发语言·c++·算法
Yang-Never39 分钟前
Open GL ES ->纹理贴图,顶点坐标和纹理坐标组合到同一个顶点缓冲对象中进行解析
android·java·开发语言·android studio·贴图