libstdc ++无法识别标准库文字

use*_*ser 5 c++ clang libstdc++

我正在尝试使用std::literals名称空间中的文字来编译一个简单的程序,但是当我尝试对其进行编译时,Clang会生成错误。

我正在尝试编译的代码:

#include <string>
#include <iostream>

using namespace std::literals;

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

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

和编译命令:

clang++ -stdlib=libstdc++ -std=c++1y a.cpp
Run Code Online (Sandbox Code Playgroud)

导致此输出:

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.
Run Code Online (Sandbox Code Playgroud)

由于各种原因,无法使用g ++或libc ++,并且我已经确认其他C ++ 14功能(即返回类型推导和二进制文字)可以工作,因此编译器没有问题,这使我相信涉及libstdc ++。

我该怎么做才能解决此问题?如果有任何不同,我使用Linux Mint 17.1。

big*_*gov 3

请记住确保您根据 C++14 编译源代码(C++11 中未提供 chrono 文字)。

clang++ -stdlib=libstdc++ -std=c++14 a.cpp
Run Code Online (Sandbox Code Playgroud)