简体   繁体   English

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

[英]libstdc++ doesn't recognise standard library literals

I'm trying to compile a simple program utilizing literals from the std::literals namespace, but Clang is generating errors when I try to compile it. 我正在尝试使用std::literals命名空间中的文字编译一个简单的程序,但是当我尝试编译时,Clang会生成错误。

The code I'm trying to compile: 我正在尝试编译的代码:

#include <string>
#include <iostream>

using namespace std::literals;

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

    return 0;
}

and the compilation command: 和编译命令:

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

which leads to this output: 这导致了这个输出:

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 libc++ are out of the question for various reasons, and I've confirmed that other C++14 features (ie. return type deduction and binary literals) work, so it's not an issue with the compiler, making me believe it involves libstdc++. 由于各种原因,使用g ++或libc ++是不可能的,我已经确认其他C ++ 14特性(即返回类型推导和二进制文字)有效,所以它不是编译器的问题,让我相信它涉及libstdc ++。

What can I do to fix this? 我该怎么做才能解决这个问题? I'm on Linux Mint 17.1 if it makes any difference. 如果它有任何区别,我在Linux Mint 17.1上。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM