string_view.copy
下面是官网的解释
size_type copy( CharT dest, size_type count, size_type pos = 0 ) const;
 (since C++17)
 (until C++20)
 constexpr size_type copy( CharT dest, size_type count,
 size_type pos = 0 ) const;
 (since C++20)
这个函数的作用就是从string_view上拷贝[pos, pos + count]个字符到dest指针上.
下面是一个演示的demo:
 	char TT[20];
    std::string str("hello world"); 
    std::string_view str_(str.c_str(), 11);
    string_view T;
    str_.copy(TT, 11);
    cout << TT << endl;
    cout << str_ << endl;
    return 0;
下面是输出:
hello world1QV
hello world
我们可以看到拷贝的时候是不会自动填充空零的 所以会在本身的数据后出现乱码 所以我们需要在进行了这个操作后自己填充空零 否则会在某些情况造成不必要的影响
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号