code_junkie

std::wstring VS std::string

Nov 13th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <cstring>
  2. #include <iostream>
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. const char text[] = "olé" ;
  7. const wchar_t wtext[] = L"olé" ;
  8.  
  9. std::cout << "sizeof(char) : " << sizeof(char) << std::endl ;
  10. std::cout << "text : " << text << std::endl ;
  11. std::cout << "sizeof(text) : " << sizeof(text) << std::endl ;
  12. std::cout << "strlen(text) : " << strlen(text) << std::endl ;
  13.  
  14. std::cout << "text(binary) :" ;
  15.  
  16. for(size_t i = 0, iMax = strlen(text); i < iMax; ++i)
  17. {
  18. std::cout << " " << static_cast<unsigned int>(static_cast<unsigned char>(text[i])) ;
  19. }
  20.  
  21. std::cout << std::endl << std::endl ;
  22.  
  23. std::cout << "sizeof(wchar_t) : " << sizeof(wchar_t) << std::endl ;
  24. //std::cout << "wtext : " << wtext << std::endl ;
  25. std::cout << "wtext : UNABLE TO CONVERT NATIVELY." << std::endl ;
  26. std::cout << "sizeof(wtext) : " << sizeof(wtext) << std::endl ;
  27. std::cout << "wcslen(wtext) : " << wcslen(wtext) << std::endl ;
  28.  
  29. std::cout << "wtext(binary) :" ;
  30.  
  31. for(size_t i = 0, iMax = wcslen(wtext); i < iMax; ++i)
  32. {
  33. std::cout << " " << static_cast<unsigned int>(static_cast<unsigned short>(wtext[i])) ;
  34. }
  35.  
  36. std::cout << std::endl << std::endl ;
  37.  
  38.  
  39. return 0;
  40. }
  41.  
  42. sizeof(char) : 1
  43. text : olé
  44. sizeof(text) : 5
  45. strlen(text) : 4
  46. text(binary) : 111 108 195 169
  47.  
  48. sizeof(wchar_t) : 4
  49. wtext : UNABLE TO CONVERT NATIVELY.
  50. sizeof(wtext) : 16
  51. wcslen(wtext) : 3
  52. wtext(binary) : 111 108 233
  53.  
  54. UCS2String ConvertToUCS2( const UTF8String &str );
  55. UTF8String ConvertToUTF8( const UCS2String &str );
Add Comment
Please, Sign In to add comment