2013-12-07 3 views
0
for(set<int> it = my_set.begin; it!= my_set.end; ++it) 
for(set<int> other = next(it); other != my_set.end; ++other) 

std :: next 때문에 컴파일되지 않습니다. 다음과 같은 루프를 구현할 수있는 방법에 대한 제안이 있습니까? 나는 사전 사용을 시도했으나 또한 효과가 없을 것이다. (루프에 구문 오류가 있음을주의하십시오.) Boost 라이브러리 기능을 사용하지 마십시오.양방향 반복자 다음

C++ 03 미리 이런 식으로 사용할 수 있습니다에서
+1

당신이 '당신 사항에 대한 자세한 명확시겠습니까 컴파일하는 것 이외에 다른 것을 성취하려고 노력하고 있습니까? –

답변

1

: 당신이 다음에 대신 사용할 수 있습니다

for(std::set<int>::iterator it = my_set.begin(); it != my_set.end(); ++it) { 
    std::set<int>::iterator copy = it; 
    std::advance(copy, 1); 
    for(; copy != my_set.end(); ++copy) { 
     std::cout << *copy << std::endl; 
    } 
} 

C++ (11)을 :

for(auto it = my_set.begin(); it != my_set.end(); ++it) { 
    for(auto other = std::next(it); other != my_set.end(); ++other) { 
     std::cout << *other << std::endl; 
    } 
} 
+0

첫 번째 예에서'++ copy'는 더 단순 해 보입니다. –

+0

다음에 작동하지 않습니다 컴파일되지 않습니다 .... 나는 두 번째 루프에서 reverse iterator를 사용하고 * 기타 == * 그것을 멈출 때까지 끝냈다. –

+0

@GoBlue 내가 말했듯이, C++ 11이 필요하다. 그래서 당신은 '컴파일하지 않을 것'이라는 말을 설명 할 수 있겠는가? –