使用自定义C++;头文件-";标准“lib”设施.h“; 我是C++新手,我正在学习这本书——Bjarne Stroustrup的第一版《C++编程原理与实践》。作者为每个程序使用头文件std_lib_facilities.h(),例如示例、演练或练习

使用自定义C++;头文件-";标准“lib”设施.h“; 我是C++新手,我正在学习这本书——Bjarne Stroustrup的第一版《C++编程原理与实践》。作者为每个程序使用头文件std_lib_facilities.h(),例如示例、演练或练习,c++,visual-studio,visual-c++,C++,Visual Studio,Visual C++,我想解决第四章第13题- 创建一个程序来查找1到100之间的所有素数。 有一种经典的方法可以做到这一点,称为“筛子” 如果你不知道这个方法,上网看看吧 把它弄起来。使用此方法编写程序 当我尝试编译我的程序时(我使用的是Visual Studio 2013),这里- //埃拉托斯烯的筛选 #包括“std_lib_facilities.h” int main() { int max=100,i=0,j=0,total=0; 向量素数(max+1,真); //用埃拉托斯烯筛法寻找素数 素数[0]=假;

我想解决第四章第13题-

创建一个程序来查找1到100之间的所有素数。 有一种经典的方法可以做到这一点,称为“筛子” 如果你不知道这个方法,上网看看吧 把它弄起来。使用此方法编写程序

当我尝试编译我的程序时(我使用的是Visual Studio 2013),这里-

//埃拉托斯烯的筛选
#包括“std_lib_facilities.h”
int main()
{
int max=100,i=0,j=0,total=0;
向量素数(max+1,真);
//用埃拉托斯烯筛法寻找素数
素数[0]=假;
素数[1]=假;

对于(i=0;i而言,此问题与标题有关

如果将此包含替换为纯标准标题,则会编译此文件:

#include <iostream>
#include <vector>
using namespace std;  // for learning purpose
#包括
#包括
使用名称空间std;//进行学习
并将
保持窗口打开()
替换为
cin.get()

您的库
“std\u lib\u facilities.h”
正在使用没有专门模板的
向量的自定义实现

专用模板使用
分配器
作为
运算符[]
的返回值


在您的例子中,它使用的是默认分配器,它从
操作符[]返回
std::Vb\u reference
-这就是你的问题。

向量是一种特殊化,结果是有问题的…切换到向量…谢谢,它现在工作得很好。你能解释一下为什么
vector
不工作吗?@marom:Hmm…,但我有一个问题,最初我没有这个头文件时,我使用了这个-
,include#include#include#include#include#include#include#include#e使用命名空间std;inline void keep_window_open(char ch;cin>>ch;)
,正如作者在第2章中所建议的,该代码当时运行良好。但当我下载并替换该标题时,出现了该错误。那么,为什么该代码会运行?新文件肯定存在一些问题(我知道与我以前使用的文件相比,这个新文件中有很多东西).有没有办法添加对
std_lib_facility.h
的更改,以便我可以使用
vector
?有两个选项:1.使用适当的引用类型实现您自己的向量专用模板2.注释掉该库中提供的向量重新实现并使用标准OneHanks。我将使用第二个,第一个是out我的范围(目前)。是否有任何方法可以添加对
“std_lib_facilities.h”
的更改,以便我可以使用
vector
1>  13_4exercise.cpp
1>c:\users\i$hu\documents\visual studio 2013\projects\c++ development\c++ development\13_4exercise.cpp(23): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\i$hu\documents\visual studio 2013\projects\c++ development\c++ development\std_lib_facilities.h(88): error C2440: 'return' : cannot convert from 'std::_Vb_reference<std::_Wrap_alloc<std::allocator<char32_t>>>' to 'bool &'
1>          c:\users\i$hu\documents\visual studio 2013\projects\c++ development\c++ development\std_lib_facilities.h(86) : while compiling class template member function 'bool &Vector<bool>::operator [](unsigned int)'
1>          c:\users\i$hu\documents\visual studio 2013\projects\c++ development\c++ development\13_4exercise.cpp(11) : see reference to function template instantiation 'bool &Vector<bool>::operator [](unsigned int)' being compiled
1>          c:\users\i$hu\documents\visual studio 2013\projects\c++ development\c++ development\13_4exercise.cpp(8) : see reference to class template instantiation 'Vector<bool>' being compiled
#include <iostream>
#include <vector>
using namespace std;  // for learning purpose