Загрузка данных


#include <iostream>
#include <string>
#include <nlohmann/json.hpp>
#include "httplib.h"

using json = nlohmann::json;

// Функция для замены подстроки в C++
void replaceAll(std::string& str, const std::string& from, const std::string& to) {
    size_t start_pos = 0;
    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
        str.replace(start_pos, from.length(), to);
        start_pos += to.length();
    }
}

int main() {
    httplib::Server svr;

    svr.get("/", [](const httplib::Request&, httplib::Response& res) {
        std::string html = "<html><body>Привет, это <span id='link-placeholder'>мой сайт</span></body></html>";
        
        // Превращаем текст "мой сайт" в кликабельную ссылку прямо из C++ кода!
        std::string linkHtml = "<a href='https://github.com' target='_blank' style='color: #3b82f6;'>мой сайт</a>";
        replaceAll(html, "мой сайт", linkHtml);

        res.set_content(html, "text/html; charset=utf-8");
    });

    svr.listen("0.0.0.0", 8080);
    return 0;
}