これは私がC++でコーディングする初心者です。このエラーを見つけたときに、この素数を見つけるプログラムを作っていました。これは最高ではないかもしれませんし、私はフィードバックに公開しています。以下のコードは正しい順序で連続しています。エラーC2660:関数は2つの引数を取らないC++
#include "stdafx.h"
using namespace std;
//finds prime numbers using Sieve of Eratosthenes algorithm
vector<int> calc_primes(const int max);
int main()
{
unsigned long long int minValue;
unsigned long long int maxValue;
bool Loop = true;
char chContinue;
vector<unsigned long long int> primes;
std::string Path;
Path = "D:\\Work\\Documents\\prime.txt";
// TODO: code your application's behavior here.
while (Loop == true)
{
cout << "Enter minimum prime number checking range (__________)" << endl ;
cin >> minValue;
cout << "Enter maximum prime number checking range (__________)" << endl ;
cin >> maxValue;
if (maxValue <= minValue)
{
cout << "Invalid selection" << endl <<endl <<endl <<endl ;
continue;
}
これは、それはそれは関数は、2つの引数を取らないいないことを私に語ってくれエラー
calc_primes(maxValue,primes);
を与える場所です。しかし、宣言では、unsigned long long intとunsigned long long intのベクトルが必要であることが明確に述べられています。
//opens file path
std::ofstream of;
of.open(Path);
//writes to file and displays numbers
for(unsigned long long int i = 0; i < primes.size(); i++)
{
if(primes.at(i) != 0)
{
cout << primes.at(i) <<" ";
of << primes.at(i) << " ";
}
}
cout << endl <<endl <<endl <<endl ;
of.close();
cout << "Continue? (y/n)" << endl ;
cin >> chContinue;
if (chContinue == 'y') {
continue;
}
else
{
if (chContinue == 'n')
{
break;
}
else
{
cout << "Invalid Selection" << endl << endl ;
}
}
}
return 0;
}
これは関数宣言です。私は&素数を入れて間違えたと思いますか?
void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
{
// fill vector with candidates
for(unsigned long long int i = 2; i < max; i++)
{
primes.push_back(i);
}
// for each value in the vector...
for(unsigned long long int i = 0; i < primes.size(); i++)
{
//get the value
unsigned long long int v = primes[i];
if (v != 0)
{
//remove all multiples of the value
unsigned long long int x = i + v;
while(x < primes.size())
{
primes[x] = 0;
x = x + v;
}
}
}
}
ありがとうございました!私は本当に初心者ですXD – TheRealOrange
あなたを歓迎して、喜んで助けてください。 –