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

libstdc++ doesn't recognise standard library literals

本文关键字:文本 标准 识别 libstdc++      更新时间:2023-10-16

我正在尝试编译一个简单的程序,使用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,如果有区别的话

记住要确保按照c++ 14编译源代码(c++ 11中没有提供计时文字)。

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