std::basic_string_view<CharT,Traits>:: copy
|
size_type copy
(
CharT
*
dest, size_type count, size_type pos
=
0
)
const
;
|
(seit C++17)
(constexpr seit C++20) |
|
Kopiert den Teilstring
[
pos
,
pos
+
rcount
)
in das Zeichenarray, auf das
dest
zeigt, wobei
rcount
der kleinere Wert von
count
und
size
(
)
-
pos
ist.
Entspricht Traits :: copy ( dest, data ( ) + pos, rcount ) .
Inhaltsverzeichnis |
Parameter
| dest | - | Zeiger auf die Ziel-Zeichenkette |
| count | - | angeforderte Teilstring-Länge |
| pos | - | Position des ersten Zeichens |
Rückgabewert
Anzahl der kopierten Zeichen.
Ausnahmen
std::out_of_range wenn pos > size ( ) .
Komplexität
Linear in
rcount
.
Beispiel
#include <array> #include <cstddef> #include <iostream> #include <stdexcept> #include <string_view> int main() { constexpr std::basic_string_view<char> source{"ABCDEF"}; std::array<char, 8> dest; std::size_t count{}, pos{}; dest.fill('\0'); source.copy(dest.data(), count = 4); // pos = 0 std::cout << dest.data() << '\n'; // ABCD dest.fill('\0'); source.copy(dest.data(), count = 4, pos = 1); std::cout << dest.data() << '\n'; // BCDE dest.fill('\0'); source.copy(dest.data(), count = 42, pos = 2); // ok, count -> 4 std::cout << dest.data() << '\n'; // CDEF try { source.copy(dest.data(), count = 1, pos = 666); // throws: pos > size() } catch (std::out_of_range const& ex) { std::cout << ex.what() << '\n'; } }
Ausgabe:
ABCD BCDE CDEF basic_string_view::copy: __pos (which is 666) > __size (which is 6)
Siehe auch
|
gibt einen Teilstring zurück
(öffentliche Elementfunktion) |
|
|
kopiert Zeichen
(öffentliche Elementfunktion von
std::basic_string<CharT,Traits,Allocator>
)
|
|
|
(C++11)
|
kopiert einen Elementbereich an einen neuen Speicherort
(Funktionstemplate) |
|
kopiert einen Puffer in einen anderen
(Funktion) |