| | |
Packing unsigned long into Unicode characters
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 16
Reputation:
Solved Threads: 1
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
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.
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?
C++ Syntax (Toggle Plain Text)
size_t i; wchar_t buf[20]; vector<unsigned long> characters; for(i = 0; i < characters.size(); i++) buf[i] = characters[i]; 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.
•
•
Join Date: Aug 2009
Posts: 16
Reputation:
Solved Threads: 1
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)
Because unicode has certain ranges of values that are invalid, I don't think that this method will work in my case.
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)
C++ Syntax (Toggle Plain Text)
wofstream outfile("output.txt", ios_base::trunc); vector<unsigned long> compressed = compress(inputstr, charmap); wchar_t* mychar; for(int i = 0; i < compressed.size(); ++i) { mychar = reinterpret_cast<wchar_t *>(&compressed[i]); outfile<<*mychar; } outfile<<endl; outfile.close();
Last edited by wheel; Sep 7th, 2009 at 3:48 pm.
![]() |
Similar Threads
- unsigned long % operation (C)
- unsigned long division operation (C)
- Unable to save unicode characters into database (ASP.NET)
- DBF files in Unicode characters (IT Professionals' Lounge)
- Problem regarding storing value into unsigned int (C)
- How to use wifstream to read a unicode file.. (C++)
- Inserting Unicode Characters into a List (Python)
Other Threads in the C++ Forum
- Previous Thread: Converting a bit stream to binary
- Next Thread: Help with tick tack toe
| Thread Tools | Search this Thread |
Tag cloud for conversion, data, packing, unicode, unsignedlong
3g 3gs access actionlistener angle apple array backup binary bits blackmail breach broadband business code combo confidentiality conversion count crime data database dataloss dataprotection decimal development display drive dropdownlist enter europe external feet fstream ftp google government hack hacking hard hardware hitachi hp information integer iphone jlabel kaspersky malware math military millimeter mining mobile module money mysql net news number numbertoword ofstream oracle packing php podcast ppc print programming python radians radix raf regex reuse search security services size spot sql sqlinjection sqlserver storage string survey symantec temperature terabyte text time tv unicode unsignedlong urllib variable warehouse web wikipedia xlwt







