2010-01-09 8 views
2

C++의 알고리즘 라이브러리에서 lexicographical_compare 함수를 사용하겠습니다.C++ lexicographical_compare에 무엇을 사용합니까?

하지만 사용하는 문장까지 무엇을 써야할지 모르겠다. 예 :

using std::lexicographical_compare ?? 

미래에 어떻게 될까요?

감사

+1

왜 물음표가 너무 많습니까? –

답변

1

당신이해야하는 것은 괜찮 - 당신은 또한 알고리즘 헤더를 포함해야합니다 : 자신에 대한 이런 일을 찾는 방법에 관해서는

#include <algorithm> 

을, 나는 강하게의 사본을 받고 추천 The C++ Standard Library.

2

그냥 "

int main() 
{ 
    int A1[] = {3, 1, 4, 1, 5, 9, 3}; 
    int A2[] = {3, 1, 4, 2, 8, 5, 7}; 
    int A3[] = {1, 2, 3, 4}; 
    int A4[] = {1, 2, 3, 4, 5}; 

    const int N1 = sizeof(A1)/sizeof(int); 
    const int N2 = sizeof(A2)/sizeof(int); 
    const int N3 = sizeof(A3)/sizeof(int); 
    const int N4 = sizeof(A4)/sizeof(int); 

    bool C12 = lexicographical_compare(A1, A1 + N1, A2, A2 + N2); 
    bool C34 = lexicographical_compare(A3, A3 + N3, A4, A4 + N4); 

    cout << "A1[] < A2[]: " << (C12 ? "true" : "false") << endl; 
    cout << "A3[] < A4[]: " << (C34 ? "true" : "false") << endl; 
} 

는 또한

// no using statement 

int main() 
{ 
    //... same as above 
    bool C12 = std::lexicographical_compare(A1, A1 + N1, A2, A2 + N2); 
    bool C34 = std::lexicographical_compare(A3, A3 + N3, A4, A4 + N4); 
    //... same as above 
} 

(예 : 스트로브 스트 룹의를 C++ 책을 읽고, 미래에 자신을 안다는 (SGI STL Doc에서 복사)를

using std::lexicographical_compare; 

및 수행 The C++ Programming Language "를 참조하십시오.

관련 문제