c++macosg++char16-t

macOS gives an Error when using char16_t / std::u16string


I tried to use char16_t / u16string on MacOS, but I get an error:

std::u16string aaa = u"-d";
const char16_t* cc = u"abcd";
Error:  "use of undeclared identifier 'u' gcc [ln...]"  

Does anyone know why that is?

I am on mac Sonoma, VSCode, C++ g++.


Solution

  • I am on mac Sonoma, VSCode, C++ g++.

    my main question is how are you compiling this? what commands are you running. i can compile this using the following commands

    main.cpp

    #include<string>
    
    int main() {
      std::u16string aaa = u"-d";
      const char16_t* cc = u"abcd";
    }
    

    command

    g++ --std=c++20 main.cpp
    

    im fairly postive that you are forgetting to set the standard version when you are building with --std=c++20 so you will be using a older standard.