_Stilgar_
asked on
BYTE*/char* to UTF8 using mbstowcs or MultiByteToWideChar?
Hi,
In a function downloading from the internet I get pieces of the data as char*/BYTE* (doesn't really matter...).
Since this will be used for downloading HTML/XML files too, I need to port convert it to UTF8. I always used MultiByteToWideChar, and I was wondering what exactly is the difference between that and mbstowcs?
Also, what is better - to use that conversion with each piece (65536 buffer), or to pile them up in std::string or whatever and then port it at once to wstring?
Thanks,
Stilgar.
In a function downloading from the internet I get pieces of the data as char*/BYTE* (doesn't really matter...).
Since this will be used for downloading HTML/XML files too, I need to port convert it to UTF8. I always used MultiByteToWideChar, and I was wondering what exactly is the difference between that and mbstowcs?
Also, what is better - to use that conversion with each piece (65536 buffer), or to pile them up in std::string or whatever and then port it at once to wstring?
Thanks,
Stilgar.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Since MultiByteToWideChar needs a buffer to make the conversion, I will need to create a new buffer for each piece in order to convert it and append it to the wstring. That means many new memory allocations and deletes against many memory re-allocations (when adding this to std::string during the actual download for later conversion). What would be your go?
Stilgar.
Stilgar.
No, you can reuse the buffer, since assingning it to a wstring copies the contents. BTW, there is also another way wor such a conversion, i.e.
#include <ctype>
#include <string>
using namespace std;
string str = "test";
wstring wstr = widen(str.begin(),str.end( ));
#include <ctype>
#include <string>
using namespace std;
string str = "test";
wstring wstr = widen(str.begin(),str.end(
ASKER
I get Cannot open include file: 'ctype': No such file or directory, and can't find widen() anywhere.
Anyway, does it work as MultiByteToWideChar(), and doesn't use the locale codepage? I need to convert to UTF8.
Stilgar.
Anyway, does it work as MultiByteToWideChar(), and doesn't use the locale codepage? I need to convert to UTF8.
Stilgar.
Then I still would go for 'MultiByteToWideChar()'. The flags make it more flexible.
ASKER
Thanks, you have been of a great help
ASKER
Stilgar.