在我的CSE课程中,我们被提供了一个头文件来编写程序。
不幸的是,当我使用该头文件编译终端时,会出现许多错误(只使用'g++'编译)。而且,当我在大学使用PuTTY时,也会出现相同的错误。 但是,如果我使用'g++ -std=c++14'编译,则不会出现这些错误。
我已经尝试在我的Mac终端上使用此命令进行编译,但它显示无法识别c++14部分。
dhcp-10-202-147-243:hw1pr1 Admin$ g++ -std=c++14 hw1pr1.cpp
error: invalid value 'c++14' in '-std=c++14'
任何关于如何让这个工作的帮助都将不胜感激。希望这些话有点意义。
下面是我在终端中使用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.
当我使用PuTTY和'g++ std=c++14'时,这个错误不会发生,程序将完全编译通过。
-std=c++1y
,直到编译器更新。由于这个初步草案被很好地跟踪,并且与最终标准几乎相同,因此应该足够好。 - Deduplicator