我有一个获取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在这个方法中使用,因为我在其中传递了不同类型的字符串.