How to use wifstream to read a unicode file..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 3
Reputation: smaity is an unknown quantity at this point 
Solved Threads: 0
smaity smaity is offline Offline
Newbie Poster

How to use wifstream to read a unicode file..

 
0
  #1
Dec 7th, 2005
Hi All,
Currently I am doing one project related to unicode file reading & writing. I got my result using CFile & using WcharToMultibyte,MultiByteToWchar conversion functions. But I have a doubt whether those functions work fine if the unichar is more than 2 bytes.

Now I want to read the file(UTF8,16(BE),16(LE)) using wifstream..

Can anyone help me???
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: How to use wifstream to read a unicode file..

 
0
  #2
Dec 7th, 2005
unichar can be more than 2 bytes? I thought it was always 2 bytes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to use wifstream to read a unicode file..

 
0
  #3
Dec 7th, 2005
Originally Posted by WolfPack
unichar can be more than 2 bytes? I thought it was always 2 bytes.

The size of wchar_t is operating system dependent. On MS-Windows wchar_t is defined as unsigned short. *nix computers it is unsigned long. And the UNICODE standards say that they intend to have 64-bit wchr_t.

That becomes a very big problem when attempting to port a UNICODE file between operating systems.

smality: No sure if this will help or not.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 3
Reputation: smaity is an unknown quantity at this point 
Solved Threads: 0
smaity smaity is offline Offline
Newbie Poster

Re: How to use wifstream to read a unicode file..

 
0
  #4
Dec 8th, 2005
Originally Posted by Ancient Dragon
The size of wchar_t is operating system dependent. On MS-Windows wchar_t is defined as unsigned short. *nix computers it is unsigned long. And the UNICODE standards say that they intend to have 64-bit wchr_t.

That becomes a very big problem when attempting to port a UNICODE file between operating systems.

smality: No sure if this will help or not.
thank you Ancient ..for providing the link, but its not enough..there is no clear idea about conversion..
this time i am trying use wistream...i willl read byte by byte......... and after getting the BOM ..then i will read all the bytes for a unichar...but if i get the byte then how to convert it back to unichar to show in textbox or listControl..

Do you have any idea regarding wistream application

thanks..
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to use wifstream to read a unicode file..

 
0
  #5
Dec 8th, 2005
I don't use c++ streams for UNICODE for the reasons you describe -- its a lot easier to use C's FILE, fopen() in binary mode, fread() and fwrite(). You don't have to worry about conversion that way. That works providing you don't want to transport the file from one operating system to another and you don't want to use another editor such as Notepad.exe to read it.


If you still want to use wfstreams, you can use mbstowcs() to convert from char* to wchar_t*, or wcstombs() to convert the other direction.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 3
Reputation: smaity is an unknown quantity at this point 
Solved Threads: 0
smaity smaity is offline Offline
Newbie Poster

Re: How to use wifstream to read a unicode file..

 
0
  #6
Dec 9th, 2005
Originally Posted by Ancient Dragon
If you still want to use wfstreams, you can use mbstowcs() to convert from char* to wchar_t*, or wcstombs() to convert the other direction.
But i got to know that wifstream/wistream uses wchar_t whiich is of 2 byte in windows system. Now the problem is that if the unicode character is more than 2 bytes (surrogates) then it is not possible to read or show unicode characters..
VC compiler is not designed in that way..

Thanks,
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to use wifstream to read a unicode file..

 
0
  #7
Dec 9th, 2005
you will probably have to write your own conversion functions that compress those 32-bit characters into 16 or 8 bit characters. But that may not work if the data requires all (or most) 32 bits to store each character, such as needed by many of the eastern languages (Chines, Japanese, etc).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC