<string_view> 연산자

이러한 연산자를 사용하여 두 string_view 개체 또는 string_view 암시적 변환이 제공되는 다른 문자열 개체(예: std::string또는 char*)를 비교합니다.

operator!=
operator>
operator>=
operator<
operator<<
operator<=
operator==
operator""sv

operator!=

연산자의 좌변에 있는 개체가 우변에 있는 개체와 같지 않은지 테스트합니다.

template <class CharType, class Traits>
bool operator!=(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator!=(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator!=(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 왼쪽에 있는 개체가 오른쪽에 있는 개체와 사전적으로 같지 않으면 false.

설명

암시적 변환은 convertible_string_type 다른 쪽으로 string_view 존재해야 합니다.

비교는 문자 시퀀스의 쌍 어휘 비교를 기반으로 합니다. 요소 수가 같고 요소가 모두 같으면 두 개체가 같습니다. 그렇지 않으면 불평등합니다.

operator==

연산자의 좌변에 있는 개체가 우변에 있는 개체와 같은지 테스트합니다.

template <class CharType, class Traits>
bool operator==(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator==(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator==(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 왼쪽에 있는 개체가 오른쪽에 있는 개체와 어휘적으로 같으면 false.

설명

암시적 변환은 convertible_string_type 다른 쪽으로 string_view 존재해야 합니다.

비교는 문자 시퀀스의 쌍 어휘 비교를 기반으로 합니다. 요소 수가 같고 요소가 모두 같으면 두 개체가 같습니다.

operator<

연산자의 좌변에 있는 개체가 우변에 있는 개체보다 작은지 테스트합니다.

template <class CharType, class Traits>
bool operator<(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator<(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator<(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 좌변에 있는 개체가 오른쪽에 있는 개체보다 어휘적으로 작으면 false.

설명

암시적 변환은 convertible_string_type 다른 쪽의 string_view 존재해야 합니다.

비교는 문자 시퀀스의 쌍 어휘 비교를 기반으로 합니다. 첫 번째 같지 않은 문자 쌍이 발견되면 해당 비교 결과가 반환됩니다. 같지 않은 문자를 찾을 수 없지만 하나의 시퀀스가 짧으면 더 짧은 시퀀스가 더 긴 시퀀스보다 작습니다. 즉, "고양이"는 "고양이"보다 작습니다.

예시

#include <string>
#include <string_view>

using namespace std;

int main()
{
    string_view sv1 { "ABA" };
    string_view sv2{ "ABAC" };
    string_view sv3{ "ABAD" };
    string_view sv4{ "ABACE" };

    bool result = sv2 > sv1; // true
    result = sv3 > sv2; // true
    result = sv3 != sv1; // true
    result = sv4 < sv3; // true because `C` < `D`
}

operator<=

연산자의 좌변에 있는 개체가 우변에 있는 개체보다 작거나 같은지 테스트합니다.

template <class CharType, class Traits>
bool operator<=(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator<=(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator<=(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 왼쪽에 있는 개체가 오른쪽의 개체보다 작거나 같은 경우 그렇지 않으면 false.

설명

operator<을(를) 참조하세요.

operator<<

출력 스트림에 string_view 씁니다.

template <class CharType, class Traits>
inline basic_ostream<CharType, Traits>& operator<<(
    basic_ostream<CharType, Traits>& Ostr, const basic_string_view<CharType, Traits> Str);

매개 변수

Ostr
출력 스트림이 기록되고 있습니다.

Str
출력 스트림에 입력할 string_view.

Return Value

출력 스트림이 기록되고 있습니다.

설명

이 연산자를 사용하여 출력 스트림에 콘텐츠를 삽입합니다(예: string_view />) std::cout.

operator>

연산자의 좌변에 있는 개체가 우변에 있는 개체보다 큰지 테스트합니다.

template <class CharType, class Traits>
bool operator>(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator>(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator>(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 왼쪽에 있는 개체가 오른쪽에 있는 개체보다 string_view 어휘적으로 크면 false.

설명

operator<을(를) 참조하세요.

operator>=

연산자의 좌변에 있는 개체가 우변에 있는 개체보다 크거나 같은지 테스트합니다.

template <class CharType, class Traits>
bool operator>=(
    const basic_string_view<CharType, Traits>& left,
    const basic_string_view<CharType, Traits>& right);

template <class CharType, class Traits>
bool operator>=(
    const basic_string_view<CharType, Traits>& left,
    convertible_string_type right);

template <class CharType, class Traits>
bool operator>=(
    convertible_string_type left,
    const basic_string_view<CharType, Traits>& right);

매개 변수

left
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

right
비교할 모든 변환 가능한 문자열 형식 또는 형식 basic_string_view 의 개체입니다.

Return Value

true 연산자의 왼쪽에 있는 개체가 오른쪽의 개체보다 크거나 같은 경우 그렇지 않으면 false.

설명

operator<을(를) 참조하세요.

operator"" sv (string_view 리터럴)

문자열 리터럴에서 생성합니다 string_view . 네임스페이스가 std::literals::string_view_literals필요합니다.

예시

using namespace std;
using namespace literals::string_view_literals;

    string_view sv{ "Hello"sv };
    wstring_view wsv{ L"Hello"sv };
    u16string_view sv16{ u"Hello"sv };
    u32string_view sv32{ U"Hello"sv };

요구 사항

/std:c++17 이상.

참고 항목

<string_view>