std::basic_string_view<CharT,Traits>::basic_string_view
: cppreference.com
<tbody>
</tbody>
constexpr basic_string_view() noexcept; |
(1) | (C++17) |
constexpr basic_string_view(const basic_string_view& other) noexcept = default; |
(2) | (C++17) |
constexpr basic_string_view(const CharT* s, size_type count); |
(3) | (C++17) |
constexpr basic_string_view(const CharT* s); |
(4) | (C++17) |
template<class It, class End> constexpr basic_string_view(It first, End last); |
(5) | (C++20) |
5)
[first, last) basic_string_view [first, last) It contiguous_iterator End It sized_sentinel_for data() std::to_address(first) size() last - first
Itcontiguous_iteratorEndItsized_sentinel_forstd::iter_value_t<It>CharTEndstd::size_t
| other | - | |
| s | - | C |
| count | - | |
| first | - | |
| last | - |
1-3,5)
4)
s Run this code
#include <iostream>
#include <string>
#include <string_view>
int main()
{
std::wstring_view wcstr_v = L"xyzzy";
char array[3] = {'B', 'a', 'r'};
std::string_view array_v(array, std::size(array));
std::string cppstr = "Foo";
std::string_view cppstr_v(cppstr);
std::cout << cppstr_v << '\n'
<< array_v << '\n'
<< wcstr_v.size() << '\n';
}
:
Foo
Bar
5
| () |