문자열의 충분을 정렬하려고합니다. 가장 간단한 방법은 모든 충분을지도에 넣는 것입니다. 메모리를 효율적으로 사용하기 위해 접미사를 (str + i)로 전달합니다. 여기서 str은 char *이고 i는 시작 위치 접미사입니다. 그러나지도가 이러한 충분을 분류하지 않는다는 것을 알게되었습니다. 여기서 일례를 진행지도 및 하위 문자열
typedef std::map < char*, int,Comparator> MapType;
MapType data;
// let's declare some initial values to this map
char* bob=(char*)"Bobs score";
char* marty=(char*) "Martys score";
data.insert(pair<char*,int>(marty+1,15));
data.insert(pair<char*,int>(bob+1,10));
MapType::iterator end = data.end();
for (MapType::iterator it = data.begin(); it != end; ++it) {
std::cout << "Who(key = first): " << it->first;
std::cout << " Score(value = second): " << it->second << '\n';
}
출력하지만, 문자열을 비교 strcmp
표준 함수 밥 + 1 + 1 마티 올바르게 작동
Who(key = first): obs score Score(value = second): 10 Who(key = first): artys score Score(value = second): 15
이다. 그것은 marty + 1이 bob + 1보다 적다고 말합니다.
는'Comparator' 무엇인가
비교 기능을 구현하기위한 올바른 방법은 다음과 같다? – hmjd
'Comparator'는 어디에 정의되어 있으며 무엇을합니까? –
물론 Comparator는 맵이 정의 된 (char *, int) ... – ShinTakezou