Soft Ware/C++ 언어!!
string 을 이용한 문자 비교함수 구현!!
달려가보자
2012. 2. 5. 10:21
#include <iostream>
#include <string>
using namespace std;
int cmp_nocase(const string &s1,const string &s2)
{
string:: const_iterator p1 = s1.begin();
string:: const_iterator p2 = s2.begin();
if(s1.size() != s2.size()) return 1;
while(p1 != s1.end() && p2 != s2.end() )
{
if(toupper(*p1) != toupper(*p2)) return 1;
p1++;
p2++;
}
return 0;
}
int main()
{
string str1="abc";
string str2="Abc";
if(str1 == str2) cout<<"대소문자 구별O - str1 과 str2는 같습니다"<<endl;
else cout<<"대소문자 구별X - str1 과 str2는 다릅니다"<<endl;
if(cmp_nocase(str1,str2)==0) cout<<"대소문자 구별O - str1 과 str2는 같습니다"<<endl;
else cout<<"대소문자 구별X - str1 과 str2는 다릅니다"<<endl;
}