std 相关问题

C ++标准库及其命名空间。与[c ++]结合使用。

std::distance 未提供“自动”创建的数组的正确值

这是我目前正在处理的一段豁免代码。 std::find 按预期完成工作,但是 std::distance 总是返回 3,我尝试了各种配置,或者有问题......

回答 1 投票 0

为什么 std::less 比 "<" for pointers?

C++ 入门,第 5 章,14.8.2,将库函数对象与算法结合使用: 向量名称表; // 指针向量 // 错误:nameTable 中的指针不相关,所以 < is

回答 1 投票 0

为什么我的终端[stdin/out]完全缓冲而不是行缓冲?

根据APUE: ISO C 要求以下缓冲特性: • 标准输入和标准输出被完全缓冲,当且仅当它们不被缓冲时 指的是交互设备。 ...

回答 1 投票 0

为什么 std::less 比 "<" for pointers?

C++ 入门,第 5 章,14.8.2,将库函数对象与算法结合使用: 向量名称表; // 指针向量 // 错误:nameTable 中的指针不相关,所以 < is

回答 1 投票 0

C++ std::成员函数的线程

我正在尝试编写一个命令行服务器,该服务器将从串行端口接收信息,解析它,并将其记录在内部对象中。 然后根据客户端的请求,服务器将返回...

回答 3 投票 0

单线程代码中是否有 std::shared_ptr 比 std::unique_ptr 更合适的用法

我对 C++11 中新内存标头的理解有点周,但据我所知,shared_ptr 是引用计数的 ptr,这使得复制它真的非常昂贵(特别是对于 exa...

回答 2 投票 0

无法推导出模板参数'T'

我试图在调用分配函数时使用 source_location::current() 作为默认参数来创建记录器库。 #包括 #包括 #包括 我试图在调用分配函数时使用 source_location::current() 作为默认参数来创建记录器库。 #include <iostream> #include <source_location> #include <type_traits> template <class T> struct log_helper { log_helper(const T& o, std::source_location sl = std::source_location::current()) : value(o), sl(sl) {} T value; std::source_location sl; }; struct ratio_t { operator double() const { return ratio; } // ratio_t(double ratio = 0) : ratio(ratio) { // printf("%p: construct\n", this); // } template<class T, class = typename std::enable_if_t<std::is_arithmetic_v<T>>> ratio_t& operator=(const log_helper<std::type_identity_t<T>>& o) { ratio = o.value; line = o.sl.line(); func = o.sl.file_name(); printf("file: %s line: %d\n", func.c_str(), line); return *this; } void clear() { ratio = 0.0f; line = 0; func.clear(); } double get_ratio() const { return ratio; } uint32_t get_line() const { return line; } std::string get_func() const { return func; } private: double ratio{0.0f}; uint32_t line{0}; std::string func; }; int main() { ratio_t a; // a.operator=<double>(log_helper(1.0)); // a.operator=<double>(1.0); // it works a = 1.0; // <- problem here } 但我收到此错误: b.cpp: In function 'int main()': b.cpp:61:9: error: no match for 'operator=' (operand types are 'ratio_t' and 'double') 61 | a = 1.0; | ^~~ b.cpp:23:14: note: candidate: 'template<class T, class> ratio_t& ratio_t::operator=(const log_helper<typename std::type_identity<_Tp>::type>&)' 23 | ratio_t& operator=(const log_helper<std::type_identity_t<T>>& o) { | ^~~~~~~~ b.cpp:23:14: note: template argument deduction/substitution failed: b.cpp:61:9: note: couldn't deduce template parameter 'T' 61 | a = 1.0; | ^~~ b.cpp:13:8: note: candidate: 'ratio_t& ratio_t::operator=(const ratio_t&)' 13 | struct ratio_t { | ^~~~~~~ b.cpp:13:8: note: no known conversion for argument 1 from 'double' to 'const ratio_t&' b.cpp:13:8: note: candidate: 'ratio_t& ratio_t::operator=(ratio_t&&)' b.cpp:13:8: note: no known conversion for argument 1 from 'double' to 'ratio_t&&' 如果我显式地实现分配,则程序将起作用。然而这并不是我所期望的。我不知道还有其他扣除。那我该如何解决呢? a.operator=<double>(log_helper(1.0)); a.operator=<double>(1.0); T 在这里处于非推导上下文中,因此您始终必须指定它。如果从声明中删除 std::type_identity_t,则可以从 T 推导出 log_helper(1.0),但仍然不能推导出 1.0。 在coliru上查看

回答 1 投票 0

有没有类似于 Windows 上的 GetTickCount() 的 C++ 标准类/函数?

unsigned int Tick = GetTickCount(); 该代码仅在 Windows 上运行,但我想使用 C++ 标准库,以便它可以在其他地方运行。 我搜索了 std::chrono,但找不到函数 l...

回答 2 投票 0

如何在C++中定义std::byte的静态数组? [重复]

我有这么长的字节列表(例如,它们不代表字符或整数)。 目前,我只能执行以下操作: 静态 const char myArray[] = {0xb8, 0xfe, 0x6c, 0x39, 0x23, ...} 我要什么...

回答 1 投票 0

basic_ios 和 basic_fstream 中的rdbuf

我正在检查 basic_ios 的文档,它有以下方法: 但是当我看到 basic_fstream 时我发现了这个: AFAIK C++ 不能有两个同名但不同 ret 的函数...

回答 1 投票 0

如何在不修改范围的情况下按降序迭代范围

有人可以告诉我我做错了什么吗?我正在尝试按降序访问元素。我无法修改输入数据,因此 std::sort 不是一个选项。 我尝试使用 std::max_element, ...

回答 1 投票 0

GCC 支持 C++23 std::print 吗?

在 CppCon 2022 上宣布,C++ 中的新官方 HelloWorld 现在是: #包括 int main() { std::print("你好世界 ”); 返回0; } 你知道吗,std::print 有用吗...

回答 3 投票 0

变体中从原始类型到用户定义类型的隐式转换

我有两个类 Int 和 Bool 模仿各自的原始类型,应该在 std::variant 中使用。几乎可以编译的例子: #包括 #包括 #包括...

回答 1 投票 0

如何使用相反的签名坐标键初始化 std::map ?

对于一些背景信息,我正在尝试使用字典查找创建快速四叉树生成算法。基本概念涉及通过二进制将坐标映射到四叉树节点

回答 1 投票 0

将指向成员函数的指针传递给父类

我有一个类派生自另一个实现回调函数映射的类 我需要将回调指针从子级传递给父级,但出现编译转换错误...

回答 2 投票 0

检查路径是否包含 C++ 中的另一个

我希望实现类似的目标 if (basePath.contains(subPath)) { // subPath是basePath的子路径 } 我知道我可以通过遍历子路径的父母,检查

回答 3 投票 0

编译包含 std::chrono 的 cpp 时出错错误:static constexpr unsignedfractional_width = {_S_fractional_width()};

我在编译以下使用 库的 C++ 代码时遇到问题: #include“log.hpp” #包括 #包括 #包括<

回答 1 投票 0

编译包含 std::chrono 的 cpp 时出错错误:static constexpr unsignedfractional_width = {_S_fractional_width()};

我在编译以下使用 库的 C++ 代码时遇到问题: #include“log.hpp” #包括 #包括 #包括<

回答 1 投票 0

std::span 中 std::dynamic_extent 的用途是什么

我知道 std::span 是静态的。它只是一堆向量/数组等的视图。 我看到了 span 的构造函数,似乎在 4-6 中使用了 std::dynamic_extent 。但在那些构造函数中还需要...

回答 1 投票 0

c++ 模块输出文件是否平台独立/跨平台?

我有一个很大的.cpp文件,需要很多分钟才能编译,我想与朋友分享它,他们有一台arm机器,我有一台x86机器。我可以将它作为我的机器和emai上的c++模块吗...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.