his_dudeness
his_dudeness

Reputation: 43

c++ u8 literal char override

I tried to override character literals in order to make them char16_t, wchar_t, char32_t, and char by using u, U, L, and u8 prefixes.It worked for all except u8. See below:

#include <iostream>
using std::cout; using std::endl;
int main(){
cout<<"\'a\'----"<<'a'<<endl;
cout<<"L \'a\'----"<<L'a'<<endl;
cout<<"u \'a\'----"<<u'a'<<endl;
cout<<"U \'a\'----"<<U'a'<<endl;
//cout<<"u8 \'a\'----"<<u8'a'<<endl;
return 0;
}

Consolse output:

'a'----a
L 'a'----97
u 'a'----97
U 'a'----97

When I uncomment the u8 line, I get following error:

'u8' was not declared in this scope prog.cpp    

Do you know why doesn't it work?

Upvotes: -1

Views: 2723

Answers (2)

yuri kilochek
yuri kilochek

Reputation: 13539

u8 chars are C++17 feature. Make sure your compiler supports it and you have enabled it.

Upvotes: 1

BoulderEE
BoulderEE

Reputation: 44

See http://www.cplusplus.com/doc/tutorial/constants/

u8 is intended for string literals while u, U, and L are intended for character literals.

In the following line you are adding the u8 prefix to a character literal. cout<<"u8 \'a\'----"<

Upvotes: 1

Related Questions