LibstdC ++ does not recognize standard library literals

I am trying to compile a simple program using literals from the namespace std::literals, but Clang generates errors when I try to compile it.

The code I'm trying to compile is:

#include <string>
#include <iostream>

using namespace std::literals;

int main()
{
    std::cout << "Hello World!"s << std::endl;

    return 0;
}

and compilation command:

clang++ -stdlib=libstdc++ -std=c++1y a.cpp

leading to this conclusion:

a.cpp:4:22: error: expected namespace name
using namespace std::literals;
                ~~~~~^
a.cpp:8:29: error: no matching literal operator for call to 'operator "" s' with arguments of
      types 'const char *' and 'unsigned long', and no matching literal operator template
        std::cout << "Hello World!"s << std::endl;
                                   ^
2 errors generated.

Using g ++ or lib ++ is out of the question for various reasons, and I have confirmed that other C ++ 14 functions (i.e. return type and binary literals) work, so this is not a problem with the compiler, I believe that it is related to libstdc ++.

What can I do to fix this? I'm on Linux Mint 17.1 if that matters.

+4
source share
1 answer

, ++ 14 ( chrono ++ 11).

clang++ -stdlib=libstdc++ -std=c++14 a.cpp
+1

All Articles