小编use*_*ser的帖子

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 ++ …

c++ clang libstdc++

5
推荐指数
1
解决办法
1249
查看次数

标签 统计

c++ ×1

clang ×1

libstdc++ ×1