gpt4 book ai didi

c++ - C++中的S后缀字符串文字给出错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:34:41 24 4
gpt4 key购买 nike

为什么这个非常简单的代码会出错:

#include <string>  
using namespace std::string_literals;
int main() {
auto s = "cat"s;
}

给出这个错误:

hello.cpp:4:16: error: expected ';' at end of declaration
auto s = "cat"s;

这个编译器是特定的,因为我正在阅读官方资源,如:https://msdn.microsoft.com/en-us/library/69ze775t.aspx .

我的机器运行 osx 我使用终端和 g++ 编译:

g++ -v 

吐出:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

我用它编译的

g++ -o hello hello.cpp

 g++ -std=c++11 hello.cpp -o hello

而且它们都显示错误。

有什么想法吗?

最佳答案

你需要使用-std=c++14

g++ -std=c++14 hello.cpp -o hello

带有 C++11 的 gcc 7.0.0:http://melpon.org/wandbox/permlink/1bqQhMueFpI8xVJq

带有 C++14 的 gcc 7.0.0:http://melpon.org/wandbox/permlink/Tf23uFqatmXkSss2

关于c++ - C++中的S后缀字符串文字给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41080987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com