std::basic_string<CharT,Traits,Allocator>::operator basic_string_view
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
operator std::basic_string_view<CharT, Traits>() const noexcept; |
(C++17以上) (C++20未満) |
|
constexpr operator std::basic_string_view<CharT, Traits>() const noexcept; |
(C++20以上) | |
std::basic_string_view<CharT, Traits>(data(), size()) によって行われたかのように構築された、 std::basic_string_view を返します。
引数
(なし)
戻り値
文字列全体の内容を表す文字列ビュー。
例
Run this code
#include <iostream>
#include <string>
#include <string_view>
void show_wstring_size(std::wstring_view wcstr_v)
{
std::cout << wcstr_v.size() << " code points\n";
}
int main()
{
std::string cppstr = "ラーメン"; // narrow string
std::wstring wcstr = L"ラーメン"; // wide string
// Implicit conversion from string to string_view
// via std::string::operator string_view:
std::string_view cppstr_v = cppstr;
std::cout << cppstr_v << '\n'
<< cppstr_v.size() << " code units\n";
// Implicit conversion from wstring to wstring_view
// via std::wstring::operator wstring_view:
show_wstring_size(wcstr);
// Warning:
// It is the programmer's responsibility to ensure that std::string_view
// does not outlive the pointed-to string!
std::string_view BAD(std::string("a temporary string")); // holds a dangling pointer!
}
出力:
ラーメン
12 code units
4 code points
関連項目
basic_string_view を構築します ( std::basic_string_view<CharT,Traits>のパブリックメンバ関数)
|