Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to output UTF-8/UTF-16 string in VS?

How to output UTF-8/UTF-16 string in VS?

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiotutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Best Kiluyar
    wrote on last edited by
    #1

    ;P;P;PHi, I'm dev in China. I want to output some string of Chinese in unicode format(UTF-8/UTF-16). So in VS2003, I write code like this to test: int _tmain(int argc, _TCHAR* argv[]) { _TCHAR* buffer = L"汉"; unsigned char* uP = (unsigned char*)buffer; return 0; } I found that the pointer 'uP' have this value: uP : 186 (BA) uP+1: 0 uP+2: 186 (BA) uP+3: 0 The unicode of '汉' is: 6C 49 The Chinese code page (GBK) in windows of '汉' is : BA BA So, the internal code in program only extand BA to BA 00 I test the code in VS2005 again, however, the internal code became 6C 49, is correct. I don't know why.:(( Remy Zhu

    M 1 Reply Last reply
    0
    • B Best Kiluyar

      ;P;P;PHi, I'm dev in China. I want to output some string of Chinese in unicode format(UTF-8/UTF-16). So in VS2003, I write code like this to test: int _tmain(int argc, _TCHAR* argv[]) { _TCHAR* buffer = L"汉"; unsigned char* uP = (unsigned char*)buffer; return 0; } I found that the pointer 'uP' have this value: uP : 186 (BA) uP+1: 0 uP+2: 186 (BA) uP+3: 0 The unicode of '汉' is: 6C 49 The Chinese code page (GBK) in windows of '汉' is : BA BA So, the internal code in program only extand BA to BA 00 I test the code in VS2005 again, however, the internal code became 6C 49, is correct. I don't know why.:(( Remy Zhu

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      You shouldn't use characters outside of the ASCII range in source code, because (as you saw) the parser may interpret the bytes differently according to the code page and character set that the app uses. Use the \x notation for the string literal: L"\x6c49"

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups