szDir
을 확인하고 싶습니다. szSelectedDir
에 있습니다. 나는 아래의 입력 값이 다르다고 생각하는 함수를 원한다. 예제 기능이 시나리오를 처리하지 못해서 좋은 해결책을 알려주십시오.문자열 비교 C++
string szSelectedDir ="C:\\Windows1\Test";
string szDir="C:\\Windows";
void IsWindowsDirectory(const string szSpecialPath, const string szSelectedPath)
{
if(szSelectedPath.compare(szSpecialPath) == 0)
{
printf("Both paths are same ");
}
else if(szSelectedPath.find(szSpecialPath) != string::npos)
{
printf("Both paths are same ");
}
else
{
printf("Both paths are different ");
}
}
'if (szSelectedPath == szSpecialPath)'운영자에게 유용합니다! – AJG85
길이를 먼저 비교하십시오. – Stu
당신이 사용하고있는'string' 클래스가 실제로'std :: string'이고'std :: string;을 사용하고 있다고 가정합니다. –