Why does this utterly simple code give error:
#include <string>
using namespace std::string_literals;
int main() {
auto s = "cat"s;
}
Give this error:
hello.cpp:4:16: error: expected ';' at end of declaration
auto s = "cat"s;
Is this compiler specific because I am reading from official resource like : https://msdn.microsoft.com/en-us/library/69ze775t.aspx.
My machine runs osx I use terminal and g++ to compile:
g++ -v
spits out:
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
I compiled it with
g++ -o hello hello.cpp
and
g++ -std=c++11 hello.cpp -o hello
and they both show errors.
Any ideas?
You need to use -std=c++14
.
g++ -std=c++14 hello.cpp -o hello
gcc 7.0.0 with C++11: http://melpon.org/wandbox/permlink/1bqQhMueFpI8xVJq
gcc 7.0.0 with C++14: http://melpon.org/wandbox/permlink/Tf23uFqatmXkSss2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With