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

时间:2015-08-28 04:20:16

标签: 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;
}

和编译命令:

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

导致此输出:

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.

由于各种原因,使用g ++或libc ++是不可能的,我已经确认其他C ++ 14特性(即返回类型推导和二进制文字)是有效的,因此它不是编译器的问题,使得我相信它涉及libstdc ++。

我该怎么做才能解决这个问题?如果它有任何区别,我会使用Linux Mint 17.1。

1 个答案:

答案 0 :(得分:2)

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

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