The C++11 `char16_t` standard type represents a character in UTF-16 encoding.
Questions tagged [char16-t]
36 questions
36
votes
4 answers
Visual Studio C++ 2015 std::codecvt with char16_t or char32_t
This code compiled OK under VS2013:
std::string Unicode::utf16_to_utf8(std::u16string utf16_string)
{
std::wstring_convert, char16_t> convert;
return convert.to_bytes(utf16_string);
}
Now with VS2015 I…

user3443139
- 654
- 1
- 7
- 11
26
votes
1 answer
Using char16_t and char32_t in I/O
C++11 introduces char16_t and char32_t to facilitate working with UTF-16- and UTF-32-encoded text strings. But the library still only supports the implementation-defined wchar_t for multi-byte I/O.
Why has support for char16_t and…

oz1cz
- 5,504
- 6
- 38
- 58
25
votes
1 answer
New unicode characters in C++0x
I'm buiding an API that allows me to fetch strings in various encodings, including utf8, utf16, utf32 and wchar_t (that may be utf32 or utf16 according to OS).
New C++ standard had introduced new types char16_t and char32_t that do not have this…

Artyom
- 31,019
- 21
- 127
- 215
14
votes
1 answer
char16_t printing
Recently I had a problem with porting a Windows application to Linux because of the wchar_t size difference between these platforms. I tried to use compiler switches, but there were problems with printing those characters (I presume that GCC wcout…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
12
votes
3 answers
C++ What does the size of char16_t depend on?
This is also related to char32_t and any intXX_t. The specification points out that:
2.14.3.2:
The value of a char16_t literal
containing a single c-char is equal to
its ISO 10646 code point value,
provided that the code point is
…

0xbadf00d
- 17,405
- 15
- 67
- 107
12
votes
3 answers
C++11 char16_t strlen-equivalent function
I have a simple question:
Is there a way to do a strlen()-like count of characters in zero-terminated char16_t array?

NoSenseEtAl
- 28,205
- 28
- 128
- 277
4
votes
2 answers
convert from char to char16_t
My config:
Compiler: gnu gcc 4.8.2
I compile with C++11
platform/OS: Linux 64bit Ubuntu 14.04.1 LTS
I have this method:
static inline std::u16string StringtoU16(const std::string &str) {
const size_t si = strlen(str.c_str());
char16_t…

mimosa
- 125
- 3
- 13
4
votes
1 answer
Clang error, no viable conversion
I am facing an issue with clang 3.1. This particular issue does not arise with GCC 4.2. The following is an example of the error that occurs:
#include
#include
#include
#include
typedef unsigned short…

joydsouza
- 43
- 3
3
votes
0 answers
How to fix linkage when use codecvt+char16_t in MSS2015?
I used char16_t type with codecvt in followind code in MSVS2015:
std::u16string utf8_to_tf16(const std::string& str)
{
std::wstring_convert, char16_t> convert;
return convert.from_bytes(str);
}
std::string…

AeroSun
- 2,401
- 2
- 23
- 46
3
votes
3 answers
char16_t and char32_t endianness
In C11, support for portable wide char types char16_t and char32_t are added for UTF-16 and UTF-32 respectively.
However, in the technical report, there is no mention of endianness for these two types.
For example, the following snippet in gcc-4.8.4…

Ryan Li
- 9,020
- 7
- 33
- 62
2
votes
1 answer
Can I use the STL regex library on strings of char16_t?
In short, what is inherently wrong with the following code?
#include
int main() {
std::regex_match(u" ", std::basic_regex{u" "});
}
It errors with
$ g++ -std=c++17 main.cpp -o main
$ ./main
terminate called after throwing an…

Enlico
- 23,259
- 6
- 48
- 102
2
votes
1 answer
to upper with char16_t array
Is there any way to do it nicely. When I try to use Boost's to_upper(), I get a std::bad_cast, so I ended with something like this:
while(str[i]!=u'\0')
{
str[i]=(char16_t)to_upper((wchar_t)str[i]);
i++;
}
I'm not even sure that this is…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
2
votes
1 answer
Why does `std::basic_ifstream` not work in c++11?
The following code works as expected. The source code, file "file.txt" and "out.txt" are all encoded with utf8. But it does not work when I change wchar_t to char16_t at the first line in main(). I've tried both gcc5.4 and clang8.0 with -std=c++11.…

kangshiyin
- 9,681
- 1
- 17
- 29
1
vote
2 answers
Assigning UTF8 char literal to char16_t - too many chars in char constant
I'm creating a UTF8 table lookup for an embedded system. The table is used to convert a UTF8 encoded character to the bitmap index in a font (array).
I'm getting a warning "multicharacter character literal (potential portability problem)". Every…

Thomas Matthews
- 56,849
- 17
- 98
- 154
1
vote
2 answers
How to handle char16_t or char32_t with printf and scanf in C?
If I write:
char a = 'A';
printf("%x %c", a, a);
it will produce the output "41 A".
Similary when I write
char32_t c = U'';
printf("%x %c", c, c); //even tried %lc and %llc
it will produce the output "1f34c L" instead of expected "1f34c "!
Is…

Sourav Kannantha B
- 2,860
- 1
- 11
- 35