Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting foreign characters into wchar_t

Status
Not open for further replies.

JediDan

Programmer
May 15, 2002
128
US
Hello,

I'm working with part of a complex system that needs to parse XML containing foreign languages. For the time being, I just need to test sending strings with foreign characters to our graphics components.

At the moment, we're handling UTF-8 strings (as char*) instead of a true multi-byte type. I would like to be able to use wcstombs() to convert some sample text for testing. However, if I do something like:

Code:
wchar_t* src = L"publicité";
size_t sz = wcslen(src);
char dest[sz]
memset(dest, '\0', sz);
wcstombs(dest, src, sz);

I get: "error: converting to execution character set: Invalid argument", on the first line. The french letter is the problem.

The question is, how do I get foreign characters into my string for testing? Do I need to use hex values? U+ values?

Any help is appreciated.
 
When I was testing some code with UTF8 I had everything in hex. Have you tried that?

Although, I just tried compiling your code on the Comeau online compiler and it worked fine (after some minor fixes):
Code:
#include <cstdlib>
#include <cstring>
#include <wchar.h>

using namespace std;

int main()
{
   wchar_t* src = L"publicité";
   size_t sz = wcslen(src);
   char dest[500];
   memset(dest, '\0', sz);
   wcstombs(dest, src, sz);
   return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top