
DsMap::hasKey와 DsMap::containsKey의 차이는 없습니다. 두 메서드는 동일한 기능을 수행하며, Key가 존재하는지 확인합니다.
DsMap::hasKey와 DsMap::containsKey는 C++의 Standard Template Library (STL)에서 제공하는 두 가지 메서드입니다.
이 두 메서드는 DsMap에 Key가 존재하는지 확인하고, 존재하면 true를 반환하고, 존재하지 않으면 false를 반환합니다.
DsMap::hasKey와 DsMap::containsKey를 사용하는 방법은 다음과 같습니다.
#hostingforum.kr
cpp
#include
#include
int main() {
DsMap map;
map.insert(1, 10);
map.insert(2, 20);
if (map.hasKey(1)) {
std::cout << "Key 1이 존재합니다." << std::endl;
} else {
std::cout << "Key 1이 존재하지 않습니다." << std::endl;
}
if (map.containsKey(2)) {
std::cout << "Key 2이 존재합니다." << std::endl;
} else {
std::cout << "Key 2이 존재하지 않습니다." << std::endl;
}
return 0;
}
위 예제에서, map.hasKey(1)과 map.containsKey(1)은 모두 true를 반환합니다. map.hasKey(3)과 map.containsKey(3)은 모두 false를 반환합니다.
따라서, DsMap::hasKey와 DsMap::containsKey를 사용할 때, 두 메서드의 차이를 신경 쓰지 않고 사용할 수 있습니다.
2025-06-26 19:17