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,结果都一样。我怎样才能运行这段代码?

ppliang69 回答:Abseil StrCat 示例导致 std::bad_alloc

这在 Godbolt 中运行良好,无论是在 gcc 下还是在 clang 下...

https://godbolt.org/z/nasjrP

因此,我敢打赌这是一个库问题:您的 main() 代码和 Abseil 和 fmt 以及您的标准库并非都在完全相同的 C++ 版本上。

本文链接:https://www.f2er.com/1090875.html

大家都在问