我写了一个简单的程序来生成素数.素数印得很好.我还尝试将每个素数放在一个向量中以便进一步处理,但不知何故,数字似乎没有进入(即push_back)向量,因为它打印出奇怪的数字而不是素数.简而言之,整个程序工作正常,只有向量有问题.请帮忙.
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
const int NUM = 300;
int main()
{
int i, j ;
int counter = 0;
bool arr[NUM] = {false}; //false == 0
vector<int> aVector;
...
cout << "\nNumber of prime numbers is " << counter << endl;
for (j=0; j<aVector.size() ; j++)
{
cout << "aVector[" << j << "] is " << aVector[j] << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)