1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
In this section the string members and string-related operations are
referenced. The subsections cover, respectively the string's initializers,
iterators, operators, and member functions. The following terminology is used
throughout this section:
itemization(
it() tt(object) is always a tt(string)-object;
it() tt(argument) is a tt(string const &) or a tt(char const *) unless
indicated otherwise. The content of an tt(argument) never is modified by the
operation processing the tt(argument);
it() tt(opos) refers to an offset into an tt(object) string;
it() tt(apos) refers to an offset into an tt(argument);
it() tt(on) represents a number of characters in an tt(object) (starting
at tt(opos));
it() tt(an) represents a number of characters in an tt(argument) (starting
at tt(apos)).
)
Both tt(opos) and tt(apos) must refer to existing offsets, or an exception
(cf. chapter ref(EXCEPTIONS)) is generated. In contrast, tt(an) and tt(on) may
exceed the number of available characters, in which case only the available
characters are considered.
Many members declare default values for tt(on, an) and tt(apos). Some members
declare default values for tt(opos). Default offset values are 0, the default
values of tt(on) and tt(an) is tt(string::npos), which can be interpreted as
`the required number of characters to reach the end of the string'.
With members starting their operations at the end of the string object's
content proceeding backwards, the default value of tt(opos) is the index of
the object's em(last) character, with tt(on) by default equal to tt(opos + 1),
representing the length of the substring em(ending) at tt(opos).
In the overview of member functions presented below it may be assumed that all
these parameters accept default values unless indicated otherwise. Of course,
the default argument values cannot be used if a function requires additional
arguments beyond the ones otherwise accepting default values.
Some members have overloaded versions expecting an initial argument of type
tt(char const *). But even if that is not the case the first argument can
em(always) be of type tt(char const *) where a parameter of tt(std::string) is
defined.
Several member functions accept em(iterators). Section ref(ITERATORS) covers
the technical aspects of em(iterators), but these may be ignored at this point
without loss of continuity. Like tt(apos) and tt(opos), iterators must refer
to existing positions and/or to an existing range of characters within the
string object's content.
All tt(string)-member functions computing indices return the
predefined constant tt(string::npos) on failure.
The ti(s) i(literal suffix) to indicate that a tt(std::string) constant is
intended when a string literal (like tt("hello world")) is used. It can be
used after declaring tt(using namespace std) or, more specific, after
declaring
hi(literals namespace)hi(string_literals namespace)
tt(using namespace std::literals::string_literals).
When string literals are used when explicitly defining or using
tt(std::string) objects the tt(s)-suffix is hardly ever required, but it may
come in handy when using the tt(auto) keyword. E.g., tt(auto str = "hello
world"s) defines tt(std::string str), whereas it would have been a tt(char
const *) if the literal suffix had been omitted.
|