1

我尝试使用 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,结果相同。我怎样才能让这段代码运行?

4

1 回答 1

1

这在gcc和clang下的godbolt中都可以正常工作......

https://godbolt.org/z/nasjrP

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

于 2021-02-06T09:49:06.737 回答