Advertisement
Guest User

Cristian

a guest
Nov 30th, 2010
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <map>
  4. #include <sstream>
  5.  
  6. std::wstring Compare(const std::wstring& first, const std::wstring second)
  7. {
  8.     int result = CompareStringW(LOCALE_INVARIANT, NORM_IGNORENONSPACE, first.c_str(), -1, second.c_str(), -1);
  9.  
  10.     std::wostringstream os;
  11.  
  12.     std::map<int, std::wstring> resultmap;
  13.     resultmap[CSTR_LESS_THAN] = L" < ";
  14.     resultmap[CSTR_EQUAL] = L" == ";
  15.     resultmap[CSTR_GREATER_THAN] = L" > ";
  16.  
  17.     if (result != 0)
  18.     {
  19.         os << first << resultmap[result] << second;
  20.     }
  21.     else
  22.     {
  23.         os << L"ERROR at CompareString, error code: 0x" << std::hex << GetLastError();
  24.     }
  25.  
  26.     return os.str();
  27. }
  28.  
  29. int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  30. {
  31.     std::wostringstream os;
  32.     os << Compare(L"voila", L"voil\xE1") << std::endl;
  33.     os << Compare(L"garcon", L"gar\xE7on") << std::endl;
  34.     os << Compare(L"kase", L"k\xE4se") << std::endl;
  35.     os << Compare(L"kase", L"kaese") << std::endl;
  36.     os << Compare(L"arsita", L"ar\x15Fi\x163\x103") << std::endl;
  37.     os << Compare(L"arsita", L"ar\x219i\x21B\x103") << std::endl;
  38.     os << Compare(L"ar\x15Fi\x163\x103", L"ar\x219i\x21B\x103") << std::endl;
  39.    
  40.     MessageBoxW(0, os.str().c_str(), L"Comparison", 0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement