std::basic_string<CharT,Traits,Allocator>::operator basic_string_view
提供: cppreference.com
< cpp | string | basic string
operator std::basic_string_view<CharT, Traits>()constnoexcept; | (C++17以上) (C++20未満) | |
constexpr operator std::basic_string_view<CharT, Traits>()constnoexcept; | (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 stringstd::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> のパブリックメンバ関数) |