如何解决Abseil StrCat 示例导致 std::bad_alloc
我尝试使用 abseil 的字符串库,但该简单示例已经无法运行并以 terminate called after throwing an instance of 'std::bad_alloc'
失败。
我使用的代码片段
#include "absl/strings/str_cat.h"
#include "fmt/core.h"
int main(){
auto s1 = absl::StrCat("A string "," another string","yet another string");
fmt::print( "{}\n",s1);
}
我将 Abseil 20200923.2 与 conan/cmake 一起使用。我尝试了 gcc 10.1 和 clang 11,结果都一样。我怎样才能运行这段代码?
解决方法
这在 Godbolt 中运行良好,无论是在 gcc 下还是在 clang 下...
因此,我敢打赌这是一个库问题:您的 main() 代码和 Abseil 和 fmt
以及您的标准库并非都在完全相同的 C++ 版本上。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。