Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: use of undeclared identifier 'u8'

Tags:

c++

utf-8

const char* hi = "hi"; // ok
const char* hi2 = u8"hi"; // compile error

It causes

error: use of undeclared identifier 'u8'

My compiler supports C++ 11.

~/Project/cpp  c++ -v
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0 
Thread model: posix
like image 328
chenzhongpu Avatar asked Nov 27 '25 15:11

chenzhongpu


1 Answers

Your compiler doesn't default to C++11 though.

[9:46pm][wlynch@watermelon /tmp] c++ -c blah.cc
blah.cc:2:19: error: use of undeclared identifier 'u8'
const char* hi2 = u8"hi"; // compile error
                  ^
blah.cc:2:21: error: expected ';' after top level declarator
const char* hi2 = u8"hi"; // compile error
                    ^
                    ;
2 errors generated.
[9:47pm][wlynch@watermelon /tmp] c++ -c -std=c++11 blah.cc
[9:47pm][wlynch@watermelon /tmp]
like image 127
Bill Lynch Avatar answered Nov 30 '25 05:11

Bill Lynch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!