[ Web Proxy ]
URL:
Viewing: http://ja.cppreference.com/cpp/string/basic_string/operator_basic_string_view [Back]  [Original]

std::basic_string<CharT,Traits,Allocator>::operator basic_string_view - cppreference.com
cppreference.com

std::basic_string<CharT,Traits,Allocator>::operator basic_string_view

: cppreference.com
 
C++
(C++20)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
 
 
std::basic_string
 
<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

()

#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>) [edit]

Web Proxy Viewer  |  New URL  |  Original Page