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. Unicode File I/O

Unicode File I/O

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 2 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.
  • S Offline
    S Offline
    Shankar Chandra Bose
    wrote on last edited by
    #1

    I've been trying to use std::wifstream to read a unicode file, like so (in a project with UNICODE on): std::wifstream wf; wchar_t wch; wf.open("unicode.txt"); while(wf.get(wch)) { std::wcout << wch; } wf.close(); Funny thing is, this *still* reads the file byte by byte, NOT wchar_t by wchar_t. This means that if you had a 000D in the file, you'd get a 00 followed by a 0D, NOT a 0D as you'd expect. On the other hand, using the C style FILE* does work properly, as: FILE* fp = _wfopen(L"unicode.txt", L"r+b"); wchar_t wch; while(!feof(fp)) { wch = fgetwc(fp); std::wcout << wch; } fcloseall(); The above code accomplishes what I want. However, as I am not too keen on using just C or Win32 functions, can someone shed somelight on what's going on? Thanks in advance, Shanker.

    L 1 Reply Last reply
    0
    • S Shankar Chandra Bose

      I've been trying to use std::wifstream to read a unicode file, like so (in a project with UNICODE on): std::wifstream wf; wchar_t wch; wf.open("unicode.txt"); while(wf.get(wch)) { std::wcout << wch; } wf.close(); Funny thing is, this *still* reads the file byte by byte, NOT wchar_t by wchar_t. This means that if you had a 000D in the file, you'd get a 00 followed by a 0D, NOT a 0D as you'd expect. On the other hand, using the C style FILE* does work properly, as: FILE* fp = _wfopen(L"unicode.txt", L"r+b"); wchar_t wch; while(!feof(fp)) { wch = fgetwc(fp); std::wcout << wch; } fcloseall(); The above code accomplishes what I want. However, as I am not too keen on using just C or Win32 functions, can someone shed somelight on what's going on? Thanks in advance, Shanker.

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      i always use the CreatFile() ... ReadFile() ... stuff to read the file in as raw data and then convert to unicode (cast a pointer to it as a _TCHAR*) works for me :) --- "every year we invent better idiot proof systems and every year they invent better idiots"

      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