Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile in c++14

So in my CSE course we are given a header file to use right now for our programs that we're writing.

Unfortunately I can't get terminal to compile using that header, it gives quite a few errors (compiling with just 'g++'). Also, when I'm at my university and I'm using PuTTY I get the same errors while using this header. However, I don't get the errors when I compile with 'g++ -std=c++14'.

I've tried compiling with this command on terminal on my mac, but it says it doesn't recognize the c++14 part.

dhcp-10-202-147-243:hw1pr1 Admin$ g++ -std=c++14 hw1pr1.cpp
error: invalid value 'c++14' in '-std=c++14'

Any help on how I could get this to work would be greatly appreciated. Hopefully this all made some sort of sense.

Here's the error I get when I compile with the header file I'm talking about in terminal with just g++.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/hash_map:212:5: warning: 
      Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
      [-W#warnings]
#   warning Use of the header <ext/hash_map> is deprecated.  Migrate to ...
    ^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:43:20: error: no matching function for call to object
      of type 'hash<char *>'
            return hash<char*>()(s.c_str());
                   ^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/__hash:39:12: note: 
      candidate function not viable: 1st argument ('const value_type *'
      (aka 'const char *')) would lose const qualifier
    size_t operator()(char *__c) const _NOEXCEPT
           ^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:112:8: warning: comparison of unsigned expression < 0
      is always false [-Wtautological-compare]
                if (i<0||size()<=i) throw Range_error(i);
                    ~^~
./std_lib_facilities_4.h:118:8: warning: comparison of unsigned expression < 0
      is always false [-Wtautological-compare]
                if (i<0||size()<=i) throw Range_error(i);
                    ~^~
3 warnings and 1 error generated.

This error doesn't happen and the program will compile fully when I use PuTTY and 'g++ std=c++14'

like image 343
Joe Avatar asked Sep 15 '14 18:09

Joe


People also ask

What is the compile command for C++?

g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file. The different “options” of g++ command allow us to stop this process at the intermediate stage.

Can you compile C as C++?

However, C is not a subset of C++, and nontrivial C programs will not compile as C++ code without modification. Likewise, C++ introduces many features that are not available in C and in practice almost all code written in C++ is not conforming C code.

What is STD C ++ 14?

C++14 is a version of the ISO/IEC 14882 standard for the C++ programming language. It is intended to be a small extension over C++11, featuring mainly bug fixes and small improvements, and was replaced by C++17. Its approval was announced on August 18, 2014.


1 Answers

There's lots of change between C++ standards, so what is valid in one revision need not be in another.

g++ defaults to -std=gnu++98 for C++, which is the decades old C++98-standard enhanced with GNU extensions (most of which are conformant).

Choose the proper revision: -std=c++1y -pedantic is a very close approximation to C++14.

What changes introduced in C++14 can potentially break a program written in C++11?

like image 175
Deduplicator Avatar answered Oct 01 '22 07:10

Deduplicator