gpt4 book ai didi

c++ - 将 std::web_view 工具引入标准有什么好处?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:14:07 27 4
gpt4 key购买 nike

根据 The Library Evolution Incubator 的最新 session ,获得大力支持的设施之一是 std::web_view

提案在 P1108R2 中描述并将用于

enables modern, natural, multimodal user interaction by leveraging existing web standards and technologies.

std::web_view w("web_view test app");
w.set_uri_scheme_handler("wv", [&](const std::string &uri, std::ostream &os) {
std::cout << "request: " << uri << "\n";
os << "<html><head><title>" << uri << "</title></head><body><p>" << uri << "</p><table>";
for (auto &a : args)
os << "<tr><td>" << a << "</td></tr>" << "\n"; // we need some kind of "to_html" utility function.
os << "</table>";
os << "<p><a href=\"" << uri << "/more.html" << "\">more</a></p>";
os << "<ul id='dl'></ul>";
os << "</body></html>";

从我提出的示例中可以看出,该设计基本上会发出 JavaScript/HMTL 代码。

我没有正确理解这种方法会产生什么好处。有人可以更深入地了解该设施吗?

最佳答案

我将首先以正确的 StackExchange 方式回答这个问题。您链接的文档在简介部分中非常清楚地说明了其动机:

Reality is that most users do not interact with applications using a command prompt (i.e., console I/O), but rather, use some graphical user interface. The C++ standard, however, provides no useful facilities in this regard, and as a result, users either need to make use of system-specific APIs, third-party libraries, or move to a different programming language.

[...]

Unfortunately, this committee has neither the time nor the expertise to address this problem by directly creating some sufficiently-comprehensive API. [...] The only feasible way forward is to reach out to the large and vibrant community tackling this issue, creating portable standards in this space, and make direct use of their efforts.

因此,简而言之,C++ 社区没有足够的资源(人员和专业知识)来实现完整的 GUI 和高级服务库。毕竟,我自己只能提到一个在功能上可以与 HTML+JS 匹敌的 C++ GUI 库,这就是 Qt 库。

现在我还想在答案中添加更多自以为是的部分,因为这个问题有点自问自答。即使没有 JavaScript,HTML 和 CSS 在几行代码中显示您想要的内容方面也非常强大。他们提出了一个广为人知的展示事物的框架。在大多数其他 GUI 框架中,您还会在“HTML 面板”中遇到 HTML,通常是在尝试呈现格式化文本时。

HTML+JavaScript 可以让初学者在编程一段时间后获得视觉上有趣的结果,这一点也很重要。在没有编程知识的情况下使用 C++ 启动 GUI 应用程序并不容易 - 您需要获取并构建一个 GUI 框架。如果我们让初学者能够通过 HTML 呈现他们用 C++ 编写的程序,社区可能会发展壮大。

关于c++ - 将 std::web_view 工具引入标准有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57126253/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com