PROGRAMMING LANGUAGE/C++
string compare함수 사용법
JC0
2021. 12. 7. 21:10
#include <iostream>
#include <string>
using namespace std;
int main()
{
// a의 첫 번째 문자와 b의 첫 번째 문자 비교
string a = "I am strinag one! ;)";
string b = "string";
cout << (int)'I';
cout << (int)'s';
if (a.compare(b) == 0)
{
cout << "I와 s는 같다" << endl;
}
else if (a.compare(b) < 0)
{
cout << "s가 크다" << endl;
}
else if (a.compare(b) > 0)
{
cout << "I가 크다" << endl;
}
return 0;
}