I just now heard about the existence of char8_t
, char16_t
and char32_t
and I am testing it out. When I try to compile the code below, g++
throws the following error:
error: use of deleted function ‘std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char32_t) [with _Traits = char_traits<char>]’
6 | std::cout << U'' << std::endl;
| ^~~~~
#include <iostream>
int main() {
char32_t c = U'';
std::cout << c << std::endl;
return 0;
}
Additionally, why can't I put the emoji into a char8_t
or char16_t
? For example, the following lines of code don't work:
char16_t c1 = u'';
char8_t c2 = u8'';
auto c3 = u'';
auto c4 = u8'';
From my understanding, emojis are UTF-8 characters and should therefore fit into a char8_t
.