不理解 VS 中 HelloWorld 的错误,当包含std_lib来自 Stroustrup 的书时
Don't understand errors on HelloWorld in VS when included std_lib from Stroustrup's book
我包括Stroustrup的Web站点的std_lib我的代码是:
#include "c:UserstheresmineusernameDocumentsVisual Studio 2017std_lib_facilities.h"
int main()
{
cout << "Hello, World!n";
return 0;
}
所以我有2个错误:
1. E1574 статическое объявление не удалось по причине "<hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning." ConsoleApplication2 c:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.10.24930includehash_map
2. C2338 <hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning. ConsoleApplication2 c:program files (x86)microsoft visual studio2017communityvctoolsmsvc14.10.24930includehash_map
从书籍开头,使用" std_lib_facilities.h",除了此std_lib的路径外,我的代码等同于本书。有人可以解释这是什么意思吗?可以通过书籍下一本书。
std_lib_facilities.h
是由stroustrup本人撰写的标头文件,可以从www.stroustrup.com下载。它是不是标准的C 标题,但显然反映了STROUSTRUP在最初几周内将语言最简单的复杂性隐藏在总数中的最简单复杂性的想法。
正如标头文件本身所说:
此标头主要使用,因此您不必了解 每一个概念一次。
i 个人认为这是一个非常糟糕的主意,对Bjarne Stroustrup的所有应有的尊重,他是一个比我所渴望的更大的天才。
标题文件充满了被认为是不良编程样式的事物(尤其是using namespace std;
,在标题文件中的全局范围中使用,或从标准容器类中派生)。它还使用过时的编译器,这些编译器可能尚未使用大量丑陋的预处理器指令正确地支持C 的某些"较新"功能。
看来,标头文件本身已经过时了(我链接到7年的历史了),我不确定STROUSTRUP是否已更新。
预处理器指令之一使您的编译器不正确地包括<hash_map>
,何时应为<unordered_map>
。当然,这很荒谬,因为您的程序只是想打印一个Hello World消息,甚至对Hash Maps都不感兴趣。
这是您的程序在正确 C 中的外观:
#include <iostream>
int main()
{
std::cout << "Hello, World!n";
return 0;
}
(请注意,return 0;
在main
中是可选的。)
但是,如果您想继续使用STROUSTRUP提供的std_lib_facilities.h
学习辅助工具,无论如何您必须在几周内取消学习,然后执行错误消息本身所说的内容:定义_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
。
最快的方法是使用源代码中的#define
:
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include "c:UserstheresmineusernameDocumentsVisual Studio 2017std_lib_facilities.h"
int main()
{
cout << "Hello, World!n";
return 0;
}
当时间到来时,将其与std_lib_facilities.h
的CC_11一起扔掉。
在C 中写这篇文章的惯用方法是:
#include <iostream>
int main() {
std::cout << "Hello World!n";
}
不应使用本书示例中的标题文件。
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 2D数组来自文本输入,中间有空格
- 通过继承类使用来自不同命名空间的运算符
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- JSON转换为nlohmann JSON-lib中的结构数组
- C++:来自外部文件的Trivia
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 针对遗留库的链接:来自预制makefile的-lgfortranbegin
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何在C++中正确引用来自不同类的类的对象?
- Qt中来自不同功能的按钮引用
- C++包含来自 #include "DevEngine/Core.h" 的错误
- Eigen c++ 三角形来自
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 来自 Android 应用程序内部的 boost 类型的 boost::wrapexcept<boost::system::system_error> 的未捕获异常
- 如何修复lib libstdc++的"std::variant"(来自GCC 9.1)不适用于Clang 8?
- 使用来自C 的LUA,无法打开标准LIB,而没有错误
- 来自 Qt Creator 中 VS2008 的 lib
- 在我的Linux中调用了哪个版本的close(),来自posix lib或内核