c++类型适配器
string_view可接收c字符串和string字符串。
#include <iostream>
#include <string>
#include <string_view>
using namespace std;
void fun(string_view str)
{
cout<<str<<endl;
}
int main()
{
fun("12345");
fun(string("12345"));
}
使用c++17编译
g++ test.cpp -std=c++17
输出结果
12345
12345