Compile in C ++ 14

So, in my CSE course, we are provided with a header file that will be used right now for our programs that we write.

Unfortunately, I can’t get the terminal to compile using this header, it gives quite a few errors (compilation using only "g ++"). Also, when I am at my university and I use PuTTY, I get the same errors when using this header. However, I do not get compilation errors with "g ++ -std = C ++ 14".

I tried to compile this command on a terminal on my mac, but it says that it does not recognize part of C ++ 14.

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 can make this work would be greatly appreciated. Hope this all made some sense.

Here is the error I get when I compile the header file that I am talking about in the terminal with g ++ only.

 /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 does not occur, and the program compiles completely when I use PuTTY and 'g ++ std = C ++ 14'

+6
source share
2 answers

There are many changes between C ++ standards, so what is really in one revision does not have to be in another.

g ++ is used by default for -std=gnu++98 for C ++ , which is an old C ++ 98 standard extended with GNU extensions (most of which are compatible).

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

What changes made in C ++ 14 could potentially break a program written in C ++ 11?

+4
source

Looking at what you say you need to use and the name format of this .cpp file, I think I'm in the same class. A year later, it seems, but here is my solution for the archive:

The std_lib_facilities.h header comes with Bjarne Stroustrup's tutorial, "Programming: Principles and Practices Using C ++". For those who did not know, Bjarne Straustrup invented C ++ (he has a good idea what he is talking about). By the way, a book is a fantastic way to learn C ++ if you have time to really read it. The std_lib_facilities.h header is simply a convenient header file for beginners in C ++, containing links to all the basic standard libraries used in the tutorial, as well as some auxiliary functions that help you to take into account possible errors or errors or are just convenient for learning (for example, function error (), which handles a simple exception for the student or adds a check "out of bounds" for vectors). This is, ultimately, just a way to allow students to jump directly into the code without having to learn the specifics of the header. Stroustrup continues to be updated with C ++ and therefore includes several libraries that require the C ++ 11 standard. The CSCE department wants its students (at least in this early class) to connect to the department’s Unix system and compiled from there to avoid confusion with downloading and updating compilers.

Previously, I already had several C ++ classes, and thus I already have g ++ installed on my Ubuntu laptop. I avoided turning std_lib_facilities on for as long as possible, as I got the same error as Creat Creator Joe, where g ++ did not recognize the “C ++ 11” part (manually, including the necessary libraries, they worked fine until we had to use the class from the tutorial which used one of the auxiliary header functions). In the end, I found a help topic on the Internet that advised me to simply upgrade the g ++ compiler to 4.7 or higher, since 4.6 and below do not support C ++ 11 (or, of course, C ++ 14). It was rather strange compared to the updates that could be used on Mac or Windows, and I doubt that the exact process will be applied, but this (was it?), Probably the problem: this is just an older version of g ++, and it Needs an update to compile C ++ 11 and later. I recommend looking for ways to update g ++ / gcc for Mac.

You know, someone else with this problem will stumble on this and have not yet solved the problem.

+1
source

Source: https://habr.com/ru/post/975312/


All Articles