wchar-t

get length of `wchar_t*` in c++

北慕城南 提交于 2019-12-04 15:13:20
问题 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 回答1: sizeof (wchar_t); Edit: I just noticed the string tag. If you want to know the size of a wchar_t string ( wchar_t * ), you want to use wcslen(3): size_t wcslen (const wchar_t *ws); 回答2: Assuming that you want to get the length of null terminated C style string, you have two options: #include

Why `strchr` seems to work with multibyte characters, despite man page disclaimer?

江枫思渺然 提交于 2019-12-04 10:20:57
From: man strchr char *strchr(const char *s, int c); The strchr() function returns a pointer to the first occurrence of the character c in the string s. Here "character" means "byte"; these functions do not work with wide or multibyte characters. Still, if I try to search a multi-byte character like é ( 0xC3A9 in UTF-8): const char str[] = "This string contains é which is a multi-byte character"; char * pos = strchr(str, (int)'é'); printf("%s\n", pos); printf("0x%X 0x%X\n", pos[-1], pos[0]); I get the following output: � which is a multi-byte character 0xFFFFFFC3 0xFFFFFFA9 Despite the warning

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

梦想的初衷 提交于 2019-12-04 09:51:07
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? Yes, no problem. It is actually somewhat documented but hard to find. The MSDN docs for the C++ libraries aren't great. It returns an interior pointer, that's not suitable for conversion to a const wchar_t* yet. You have to pin the pointer so the garbage collector cannot move the

QChar to wchar_t

会有一股神秘感。 提交于 2019-12-04 06:32:29
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++) { myArray[x] = mystring.at(x).toLatin1(); cout << mystring.at(x).toLatin1(); // checks the char at index x (fine) } cout << "myArray : " << myArray << "\n"; // doesn't give me correct value return 0; } Oh and before someone suggests using the .toWCharArray(wchar_t* array) function, I've tried that and

conflicts: definition of wchar_t string in C++ standard and Windows implementation?

走远了吗. 提交于 2019-12-04 03:10:14
问题 From c++2003 2.13 A wide string literal has type “ array of n const wchar_t ” and has static storage duration, where n is the size of the string as defined below The size of a wide string literal is the total number of escape sequences, universal-character-names, and other characters, plus one for the terminating L’\0’. From c++0x 2.14.5 A wide string literal has type “ array of n const wchar_t ”, where n is the size of the string as defined below The size of a char32_t or wide string literal

UTF-8 Compatibility in C++

左心房为你撑大大i 提交于 2019-12-04 01:16:45
I am writing a program that needs to be able to work with text in all languages. My understanding is that UTF-8 will do the job, but I am experiencing a few problems with it. Am I right to say that UTF-8 can be stored in a simple char in C++? If so, why do I get the following warning when I use a program with char , string and stringstream : warning C4566: character represented by universal-character-name '\uFFFD' cannot be represented in the current code page (1252) . (I do not get that error when I use wchar_t , wstring and wstringstream .) Additionally, I know that UTF is variable length.

get length of `wchar_t*` in c++

巧了我就是萌 提交于 2019-12-03 09:27:53
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 sizeof (wchar_t); Edit: I just noticed the string tag. If you want to know the size of a wchar_t string ( wchar_t * ), you want to use wcslen(3) : size_t wcslen (const wchar_t *ws); Assuming that you want to get the length of null terminated C style string, you have two options: #include <cwchar> and use std::wcslen (dimObjPrefix); , or #include <string> and use std::char_traits<wchar_t>::length

Does the C++ standard mandate an encoding for wchar_t?

走远了吗. 提交于 2019-12-03 08:19:31
Here are some excerpts from my copy of the 2014 draft standard N4140 22.5 Standard code conversion facets [locale.stdcvt] 3 For each of the three code conversion facets codecvt_utf8 , codecvt_utf16 , and codecvt_utf8_utf16 : (3.1) — Elem is the wide-character type, such as wchar_t , char16_t , or char32_t . 4 For the facet codecvt_utf8 : (4.1) — The facet shall convert between UTF-8 multibyte sequences and UCS2 or UCS4 (depending on the size of Elem ) within the program. One interpretation of these two paragraphs is that wchar_t must be encoded as either UCS2 or UCS4. I don't like it much

Print wchar to Linux console?

梦想与她 提交于 2019-12-03 03:12:08
My C program is pasted below. In bash, the program print "char is ", Ω is not printed. My locale are all en_US.utf8. #include <stdio.h> #include <wchar.h> #include <stdlib.h> int main() { int r; wchar_t myChar1 = L'Ω'; r = wprintf(L"char is %c\n", myChar1); } This was quite interesting. Apparently the compiler translates the omega from UTF-8 to UNICODE but somehow the libc messes it up. First of all: the %c -format specifier expects a char (even in the wprintf -version) so you have to specify %lc (and therefore %ls for strings). Secondly if you run your code like that the locale is set to C

Inconsistency in definitions of fputwc(), putwc() and putwchar() in glibc

谁都会走 提交于 2019-12-02 04:15:26
问题 Why fputwc() , putwc() and putwchar() take argument of type wchar_t instead of wint_t ? This contradicts corresponding non-wide character functions fputc() , putc() and putchar() , which take int , not char . 回答1: That is because wchar_t is required to hold an WEOF value and char is not required to hold an EOF value. For char , the fputc() , putc() and putchar() functions need to accept values which can hold both values in the unsigned char and EOF range, where EOF can be a negative number so