wchar-t

Separating null byte separated UNICODE C string.

First off, this is NOT a duplicate of: http://stackoverflow.com/questions/1911053/turn-a-c-string-with-null-bytes-into-a-char-array , because the given answer doesn't work when the char *'s are Unicode. I think the problem is that because I am trying to use UTF-8 encoded char *'s instead of ASCII char *'s, and the length of each charact...

get length of `wchar_t*` in c++

Please, how can I find out the length of a variable of type wchar_t* in c++? code example below: wchar_t* dimObjPrefix = L"retro_"; I would like to find out how many characters dimObjPrefix contains ...

Whats the easiest way to convert a long in C to a char*?

What is the clean way to do that in C? wchar_t* ltostr(long value) { int size = string_size_of_long(value); wchar_t *wchar_copy = malloc(value * sizeof(wchar_t)); swprintf(wchar_copy, size, L"%li", self); return wchar_copy; } The solutions I came up so far are all rather ugly, especially allocate_properly_size_whar_t u...

C++ template function specialization using TCHAR on Visual Studio 2005

I'm writing a logging class that uses a templatized operator<< function. I'm specializing the template function on wide-character string so that I can do some wide-to-narrow translation before writing the log message. I can't get TCHAR to work properly - it doesn't use the specialization. Ideas? Here's the pertinent code: // Log.h head...

Is it possible to get a pointer to String^'s internal array in C++/CLI?

The goal is to avoid copying the string data when I need a const wchar_t*. The answer seems to be yes, but the function PtrToStringChars doesn't have its own MSDN entry (it's only mentioned in the KB and blogs as a trick). That made me suspicious and I want to check with you guys. Is it safe to use that function? ...

swprintf chokes on characters outside 8-bit range

This happens on OS X, though I suspect it applies to any UNIX-y OS. I have two strings that look like this: const wchar_t *test1 = (const wchar_t *)"\x44\x00\x00\x00\x73\x00\x00\x00\x00\x00\x00\x00"; const wchar_t *test2 = (const wchar_t *)"\x44\x00\x00\x00\x19\x20\x00\x00\x73\x00\x00\x00\x00\x00\x00\x00"; In the debugger, test1 look...

How to convert wchar_t** to char**?

I get argv as wchar_t** (see below), because I need to work with unicode, but I need to convert it to char **. How can I do that? int wmain(int argc, wchar_t** argv) { ...

proper style for interfacing with legacy TCHAR code

I'm modifying someone else's code which uses TCHAR extensively. Is it better form to just use std::wstring in my code? wstring should be equivalent to TString on widechar platforms so I don't see an issue. The rationale being, its easier to use a raw wstring than to support TCHAR... e.g., using boost:wformat. Which style will be more c...

Writting Unicode Characters to an OStream

I'm working with unicode/wide characters and I'm trying to create a toString method (Java ::toString equiv). Will ostream handle wide characters, if so is there a way to warn the consumer of the stream that it is unicode coming out of it? ...

Unicode, char pointers and wcslen

Hi, I've been trying to use the cpw library for some graphics things. I got it set up, and I seem to be having a problem compiling. Namely, in a string header it provides support for unicode via #if defined(UNICODE) | defined(_UNICODE) #define altstrlen wstrlen #else #define altstrlen strlen Now, there's no such thing as wstrlen o...

isalpha equivalent for wchar_t

what is the equivalent function for isalpha or isalnum using wchar_t? wctype ? an example would be nice also thanks ...

C++: Files, encodings and datatypes

---- PLEASE CLOSE ---- ------ Edit --------- I found where the problem is. I'm going to start a new question for the real problem .... ----------------------   Hi, My Situation: Linux (Ubuntu 10.04) gcc But it has to be platform independent I have a text file (UTF-8) with special characters like ¥ © ® Ỳ È Ð. I have a std:...

Need to convert char* (pointer) to wchar_t* (pointer)

I am doing some serial port communcation to a computer controlled pump and the createfile function I used to communicate requires the com port name to be parsed as a wchar_t pointer. I am also using QT to create a form and aquire the com port name as a QString. This QString is converted to a char array and pointed to as follows: c...

QChar to wchar_t

Hello, I need to convert a QChar to a wchar_t I've tried the following: #include <cstdlib> #include <QtGui/QApplication> #include <iostream> using namespace std; int main(int argc, char** argv) { QString mystring = "Hello World\n"; wchar_t myArray[mystring.size()]; for (int x=0; x<mystring.size(); x++) { my...

Deprecated conversion from string const. to wchar_t*

Hello I have a pump class that requires using a member variable that is a pointer to a wchar_t array containing the port address ie: "com9". The problem is that when I initialise this variable in the constructor my compiler flags up a depreciated conversion warning. pump::pump(){ this->portNumber = L"com9";} This works fine but th...

Problem converting char to wchar_t (length wrong)

I am trying to create a simple datastructure that will make it easy to convert back and forth between ASCII strings and Unicode strings. My issue is that the length returned by the function mbstowcs is correct but the length returned by the function wcslen, on the newly created wchar_t string, is not. Am I missing something here? typed...