2014-04-27 2 views
1

두 문자열 사이의 교차를 찾으려고합니다. 나는 다음과 같은 코드를 사용하고 있습니다 :표현식 : 순서가 지정되지 않았습니다.

std::string a = "asd", b = "afd"; 

std::string intersect; 
std::set_intersection(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(intersect)); 

성공적으로 컴파일하지만 다음과 같은 오류와 함께 프로그램 인스턴트 충돌을 실행 한 후에이 문제의 원인이 무엇

enter image description here

어떤 제안을? 당신은 a 분류한다

+1

추가 할 수 있습니다. – joc

답변

2

std::set_intersection()에게 전달하기 전에 먼저 b : -과 set_intersection에 대한 입력을 정렬 할 필요가

template< class InputIt1, class InputIt2, class OutputIt > OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first); (1) template< class InputIt1, class InputIt2, class OutputIt, class Compare > OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp); (2)

Constructs a sorted range beginning at d_first consisting of elements that are found in both sorted ranges [first1, last1) and [first2, last2) . The first version expects both input ranges to be sorted with operator< , the second version expects them to be sorted with the given comparison function comp.

그래서, 오류 메시지를 알려줍니다

std::sort(a.begin(), a.end()); 
std::sort(b.begin(), b.end()); 
관련 문제