Packing unsigned long into Unicode characters

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

Join Date: Aug 2009
Posts: 16
Reputation: wheel will become famous soon enough wheel will become famous soon enough 
Solved Threads: 1
wheel wheel is offline Offline
Newbie Poster

Packing unsigned long into Unicode characters

 
0
  #1
Sep 7th, 2009
Hello!

I'm wondering how to go about packing data from an std::vector<unsigned long> into valid unicode (UTF-8) characters. So far, I've tried writing the unsigned long data directly to a text file, but that usually results in invalid characters.

(I don't actually need to store the data in unsigned long form, I just thought it might make converting the data to unicode characters easier.)

Sorry about not posting any code, but I don't think what I have (above) is worth posting.

Thanks
Last edited by wheel; Sep 7th, 2009 at 5:17 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,546
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: 1484
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Packing unsigned long into Unicode characters

 
-7
  #2
Sep 7th, 2009
UNICODE characters is wchar_t, which on MS-Windows is unsigned short and on some other operating systems can be unsigned long. So why not just do something like this?
  1. size_t i;
  2. wchar_t buf[20];
  3. vector<unsigned long> characters;
  4. for(i = 0; i < characters.size(); i++)
  5. buf[i] = characters[i];
  6. buf[i] = 0;
Last edited by Ancient Dragon; Sep 7th, 2009 at 9:17 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 16
Reputation: wheel will become famous soon enough wheel will become famous soon enough 
Solved Threads: 1
wheel wheel is offline Offline
Newbie Poster

Re: Packing unsigned long into Unicode characters

 
0
  #3
Sep 7th, 2009
Thanks for the reply!

I've tried a similar method, and it didn't work (either resulted in errors when opening the file in a unicode text editor, or simply didn't print the characters). Here's my similar code: (with namespace std, of course)
  1. wofstream outfile("output.txt", ios_base::trunc);
  2. vector<unsigned long> compressed = compress(inputstr, charmap);
  3. wchar_t* mychar;
  4. for(int i = 0; i < compressed.size(); ++i) {
  5. mychar = reinterpret_cast<wchar_t *>(&compressed[i]);
  6. outfile<<*mychar;
  7. }
  8. outfile<<endl;
  9. outfile.close();
Because unicode has certain ranges of values that are invalid, I don't think that this method will work in my case.
Last edited by wheel; Sep 7th, 2009 at 3:48 pm.
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



Tag cloud for conversion, data, packing, unicode, unsignedlong
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC