#include
<algorithm>
bool lexicographical_compare (In first, In last, In2 first2, In2 last2) bool lexicographical_compare (In first, In last, In2 first2, In2 last2, Binary comp) bool lexicographical_compare (Exec pol, In first, In last, In2 first2, In2 last2) bool lexicographical_compare (Exec pol, In first, In last, In2 first2, In2 last2, Binary comp) bool ranges::lexicographical_compare (Range1 r1, Range2 r2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) bool ranges::lexicographical_compare (In first, In last, In2 first2, In2 last2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {})
Ist wahr, wenn der Bereich [first,last) lexikographisch vor [first2,last2) einzuordnen ist.
first | Anfang eines Bereiches |
last | Ende eines Bereiches |
first2 | Anfang des zweiten Bereiches |
last2 | Ende des zweiten Bereiches |
comp | Sortierkriterium (Vorgabe = less ) |
proj | einstelliger Funktor (Vorgabe = std::identity ) |
pol | parallele Ausführungsart |
Rückgabewert: true
, wenn bei evtl. gleichen Anfangselementen
als das entsprechende Element des zweiten Bereiches.
Andernfalls ist das Ergebnis false
,
insbesondere auch bei übereinstimmenden Folgen gleicher Länge.
-
#include <algorithm> #include <string> #include <iostream> int main() { std::string s, t; std::cout << "Gib zwei Worte ein: "; std::cin >> s >> t; if (std::lexicographical_compare(begin(s), end(s), begin(t), end(t))) { std::cout << s << "steht vor " << t << " im Lexikon.\n"; } else { std::cout << s << "steht nicht vor " << t << " im Lexikon.\n"; } }