小编Pav*_*bev的帖子

使用带有api的std :: string_view,期望null终止字符串

我有一个获取std::string_view和使用函数的方法,它以null终止的字符串作为参数.例如:

void stringFunc(std::experimental::string_view str) {
    some_c_library_func(/* Expects null terminated string */);
}
Run Code Online (Sandbox Code Playgroud)

问题是,处理这种情况的正确方法是什么?是str.to_string().c_str()唯一的选择吗?我真的想std::string_view在这个方法中使用,因为我在其中传递了不同类型的字符串.

c++ c++17

10
推荐指数
3
解决办法
3127
查看次数

标签 统计

c++ ×1

c++17 ×1