GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_string_view::substr(3) C++ Standard Libary std::basic_string_view::substr(3)

std::basic_string_view::substr - std::basic_string_view::substr


constexpr basic_string_view substr( size_type pos = 0, (since C++17)
size_type count = npos ) const;


Returns a view of the substring [pos, pos + rcount), where rcount is the smaller of
count and size() - pos.


pos - position of the first character
count - requested length


View of the substring [pos, pos + rcount).


std::out_of_range if pos > size()


Constant.

// Run this code


#include <cstddef>
#include <iostream>
#include <stdexcept>
#include <string_view>


int main()
{
typedef std::size_t count_t, pos_t;


constexpr std::string_view data{"ABCDEF"};


std::cout << data.substr() << '\n'; // ABCDEF
std::cout << data.substr(pos_t(1)) << '\n'; // BCDEF
std::cout << data.substr(pos_t(2), count_t(3)) << '\n'; // CDE


std::cout << data.substr(pos_t(4), count_t(42)) << '\n'; // EF
// count -> 2 == size() - pos == 6 - 4


try {
data.substr(pos_t(666), count_t(1)); // throws: pos > size()
}
catch(std::out_of_range const& ex) {
std::cout << ex.what() << '\n';
}
}


ABCDEF
BCDEF
CDE
EF
basic_string_view::substr: __pos (which is 666) > __size (which is 6)


copy copies characters
(C++17) (public member function)
find find characters in the view
(C++17) (public member function)
substr returns a substring
(public member function of std::basic_string<CharT,Traits,Allocator>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.