为什么不能初始化此布尔向量?请看这段代码

时间:2018-09-03 20:33:51

标签: c++

我正在使用Bjarne Stroustrup的书“编程-使用C ++的原理和实践”,并且正在第四章中进行练习。我正在尝试使用“ Eratosthenes筛”查找素数。我认为,除了向量之外,其他一切都正确。我以前从未使用过布尔类型。我相信我拥有本书中最新的头文件。如果您需要该代码,我会提出。我怀疑您会需要它。

#include "std_lib_facilities.h"
int main()
{
vector<bool>number_list;

for(int counter=0; counter<100; ++counter)
    number_list.push_back(false);

int prime=2;

for(int counter=0; counter<100; ++counter)
    {if(number_list[counter]==false)
        {prime=counter+2;

         for(int counter=prime*2-2; counter<100; counter+=prime)
             number_list[counter]=true;}}

0 个答案:

没有答案