Boost是一系列旨在用于C ++的高质量库。 Boost是免费的,通常被认为是“第二标准库”。
我正在尝试在 Windows PowerShell 上为 CI 系统下载并执行安装程序(Boost 1.74): 我正在使用 Invoke-WebRequest,然后只需执行该程序即可。 然而它告诉我...
任何更好的方法来改进代码以保持 aiso::async_send 使用的底层内存块有效
我曾经写过下面的代码片段来异步发送tcp数据。 无效对话::do_write(std::string str) { 自动对话指针(shared_from_this()); m_socket.async_send(asio::buff...
我有一个用C++编写的iOS静态框架,下面的代码使用boost mmaped_file进行一些操作。 当 open 失败时,boost 会抛出异常。在我的测试中效果很好
如何仅从单个 Chocolatey 软件包安装 Boost 64 位?
目前,我正在使用 Chocolatey 安装 Boost, choco 安装-y boost-msvc-14.2 --版本 1.74.0 这将安装该库的 32 位和 64 位版本。 我相信我不需要 32 位 v...
使用 Conan 2.0 构建 Boost 使用 MSVC 失败
我正在使用以下设置: 视觉工作室: Microsoft Visual Studio Professional 2022(64 位)- 当前 版本17.10.2 柯南: 柯南2.4.1版 这是我的柯南简介: [设置] 拱=x...
make_parallel_group:它可以与线程池“post”一起使用吗?
我想要一个函数,将输入范围中的元素并行应用到处理程序。一个可能的实现是: 模板 无效
std::to_string、boost::to_string 和 boost::lexical_cast 有什么区别<std::string>?
boost::to_string(在 boost/exception/to_string.hpp 中找到)的用途是什么?它与 boost::lexical_cast 和 std::to_string 有什么不同?
错误:使用 Boost 的 iterator_facade 时,“std::iterator_traits”中没有名为“value_type”的类型
我正在使用 Boost 1.84 和 C++17,并且创建了一个继承自 boost::iterator_facade 的 polymorphic_iterator 类。这是我的课程的简化版本: 命名空间迭代器 { 模板<
boost.graph:在过滤图上使用 kruskal 算法无法编译
我正在使用boost graph,我正在尝试在过滤图上运行kruskal_minimum_spanning_tree算法。遗憾的是它无法编译。 这是显示问题的示例: #包括 我正在使用 boost graph,并且尝试在过滤图上运行 kruskal_minimum_spanning_tree 算法。遗憾的是它无法编译。 这是一个显示问题的示例: #include <boost/graph/adjacency_list.hpp> #include "boost/graph/graph_utility.hpp" #include <boost/graph/filtered_graph.hpp> #include <boost/property_map/function_property_map.hpp> #include <boost/graph/kruskal_min_spanning_tree.hpp> using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>; using Vertex = boost::graph_traits<Graph>::vertex_descriptor; using Edge = boost::graph_traits<Graph>::edge_descriptor; int main() { Graph G; // create a complete graph with 4 nodes. for (int i = 0; i < 5 ; ++i) { for (int j = i+1; j< 5; ++j) boost::add_edge(i, j, G); } boost::print_graph(G); /* 0 <--> 1 2 3 4 1 <--> 0 2 3 4 2 <--> 0 1 3 4 3 <--> 0 1 2 4 4 <--> 0 1 2 3 */ struct Filter { bool operator()(Vertex const & v) const { if (v != 0 && v != 2) return true; return false; } }; boost::filtered_graph G_f(G, boost::keep_all(), Filter()); boost::print_graph(G_f); /* 1 <--> 3 4 3 <--> 1 4 4 <--> 1 3 */ auto wmap = boost::make_function_property_map<Edge, double>([](Edge const & e){ return 1.0; }); std::vector<Edge> mst; // Works: kruskal_minimum_spanning_tree(G, std::back_inserter(mst), boost::weight_map(wmap)); // Does not compile: kruskal_minimum_spanning_tree(G_f, std::back_inserter(mst), boost::weight_map(wmap)); double result = 0; for (auto const & e : mst) result += wmap[e]; std::cout << result << "\n"; // prints 4 } 我可以将 kruskals 算法应用于原始图,并且效果很好。 但是当我尝试在过滤后的图表上运行它时,我收到以下编译错误: error C2039: 'type': is not a member of 'boost::vertex_property_type<Graph>' error C2039: [ error C2039: with error C2039: Graph=boost::filtered_graph<Graph,boost::keep_all,main::Filter> error C2039: ] error C3203: 'type': unspecialized class template can't be used as a template argument for template parameter 'Property', expected a real type 我做错了什么? 我认为问题在于,为了运行 Kruskal 算法,你的图应该有边权重,但你的示例中并非如此: using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>; using Vertex = boost::graph_traits<Graph>::vertex_descriptor; using Edge = boost::graph_traits<Graph>::edge_descriptor; 应该是这样的: using namespace boost; typedef adjacency_list< vecS, vecS, undirectedS, no_property, property< edge_weight_t, int > > Graph; typedef graph_traits< Graph >::edge_descriptor Edge; typedef std::pair< int, int > E; 请查看官方文档中的完整示例: https://www.boost.org/doc/libs/1_85_0/libs/graph/example/kruskal-example.cpp
当我想使用boost时,遇到编译错误,并且在/usr/include/boost中找不到cstddef: 在 server.c:10:0 包含的文件中: /usr/include/boost/config/select_stdlib_config.hpp:17:19:致命
我在 Eclipse 中编译 C++ 项目时遇到一些问题。 它运行良好,但是当我包含 boost 头文件(algorithm/string.hpp)时,它会显示以下错误: 16:25:53 **** 增量Bu...
boost::asio::placeholders::error的正确使用
可以在此页面看到下面的代码片段。 #包括 #包括 #包括 #包括 使用名称...
Boost Asio:传递给 boost::asio::post 的 Executor 和 CompletionToken 的关联执行器有什么区别?
对于像post和dispatch这样的方法,有一个重载只需要一个CompletionToken,另一个重载还需要一个Executor。据我所知,没有 Executor 的重载就像
Boost Asio:如何在多个独立的链中运行单个处理程序?
想象一下,在多线程上下文中,我们有三个或更多独立的链,每个链序列化对不同资源的访问: boost::asio::io_context ioc; 自动 io_ex = ioc.get_executor(); 自动str...
co_await boost::asio::this_coro::executor 产生什么执行器?
boost::asio::this_coro::executor 的文档指出它是一个 返回当前协程执行器的 Awaitable 对象。 对我来说,这似乎有点模糊,一旦多个
std::移动 unique_ptr 的 boost::flat_map
我希望能够在构造函数中初始化一个包含 boost::container::flat_map> 的类。例子: 类 MapHolder { 民众:
在尝试 boost::asio::awaitable 和 Executors 时,我不断观察到一些相当令人困惑的行为,我想更好地理解它们 准备 请看下面的内容
我在 boost::process 中启动 FFmpeg 并每 n 秒从中获取数据。 如果我使用 Ctrl+C 在控制台中终止应用程序或 FFmpeg,FFmpeg 会将其所有数据刷新到标准输出。 但是,如果我终止 b...
我使用视觉工作室。该项目在 Linux 机器上组装并启动。但是如果你在没有安装boost的机器上运行它,就会出现错误“加载共享库时出错
我有一个 C# 中的 get 请求,我需要将其转换为 C++ (boost) C# 中的获取请求: 使用系统文本; 使用Newtonsoft.Json; 班级计划 { 私有静态只读字符串键=“ 我有一个 C# 中的 get 请求,我需要将其转换为 C++ (boost) 在 C# 中获取请求: using System.Text; using Newtonsoft.Json; class Program { private static readonly string key = "<your-translator-key>"; private static readonly string endpoint = "https://api.cognitive.microsofttranslator.com"; // location, also known as region. // required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page. private static readonly string location = "<YOUR-RESOURCE-LOCATION>"; static async Task Main(string[] args) { // Input and output languages are defined as parameters. string route = "/translate?api-version=3.0&from=en&to=fr&to=zu"; string textToTranslate = "I would really like to drive your car around the block a few times!"; object[] body = new object[] { new { Text = textToTranslate } }; var requestBody = JsonConvert.SerializeObject(body); using (var client = new HttpClient()) using (var request = new HttpRequestMessage()) { // Build the request. request.Method = HttpMethod.Post; request.RequestUri = new Uri(endpoint + route); request.Content = new StringContent(requestBody, Encoding.UTF8 "application/json"); request.Headers.Add("Ocp-Apim-Subscription-Key", key); // location required if you're using a multi-service or regional (not global) resource. request.Headers.Add("Ocp-Apim-Subscription-Region", location); // Send the request and get response. HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); // Read response as a string. string result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } } } 在boost中获取请求:https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/quick_start.html 由于额外输入数据量巨大,不清楚如何使用它们 这应该是一个好的开始: #include <boost/asio/ssl.hpp> #include <boost/beast.hpp> #include <boost/beast/ssl.hpp> #include <boost/json.hpp> #include <iostream> namespace net = boost::asio; namespace beast = boost::beast; namespace http = beast::http; namespace ssl = net::ssl; namespace json = boost::json; using tcp = net::ip::tcp; int main() { std::string const my_translator_key = "YOUR_TRANSLATOR_KEY"; std::string const my_resource_location = "westus"; net::io_context ioc; tcp::resolver resolver{ioc}; auto eps = resolver.resolve("api.cognitive.microsofttranslator.com", "https"); // Input and output languages are defined as parameters. std::string route = "/translate?api-version=3.0&from=en&to=fr&to=zu"; std::string textToTranslate = "I would really like to drive your car around the block a few times!"; json::array body = {{{"Text", textToTranslate}}}; std::string requestBody = json::serialize(body); http::request<http::string_body> request; request.method(http::verb::post); request.target(route); request.set(http::field::content_type, "application/json"); request.set(http::field::user_agent, "Beast"); request.set(http::field::accept, "application/json"); request.set(http::field::host, "api.cognitive.microsofttranslator.com"); request.set(http::field::authorization, "Ocp-Apim-Subscription-Key: " + my_translator_key); request.set(http::field::authorization, "Ocp-Apim-Subscription-Region: " + my_resource_location); request.body() = requestBody; request.prepare_payload(); tcp::socket s{ioc}; net::connect(s, eps); ssl::context ctx{ssl::context::tlsv12_client}; boost::beast::ssl_stream<tcp::socket> stream{std::move(s), ctx}; stream.handshake(ssl::stream_base::client); http::write(stream, request); beast::flat_buffer buffer; http::response<http::string_body> response; http::read(stream, buffer, response); std::cout << response.body() << std::endl; } 显然没有端点密钥我无法测试它: