0

This is my code...

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

bool searchVect(vector<int>, int);


int main()
{
	bool answer;
	int value;
	vector<int> vect = {13579,  26791,  26792,  33445,  55555,
						62483,  77777,  79422,  85647,  93121};
	
	cout << "Enter the number to determine if there is a winner. \n";
	cin >> value;

	answer = searchVect(vect, value);

	cout << "The answer of whether it was found is " << answer << endl;

	return 0;
}

bool searchVect(vector<int> vect, int v) 
{
	bool answer = false;

	answer = binary_search(vect.begin(), vect.end(), v);
	return answer;
}

What i don't understand is how come the binary_search isn't recognized inside the function. If i need to pass something to the function then what? Also it possibe to make the function above a template with the class vector inside the function already being a template, so that both templates work in unison, the function and the vector class template that was passed to the function?

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by VernonDozier
0

You're missing a header file where the definition of binary_search is
add #include <algorithm>

0
vector<int> vect = {13579,  26791,  26792,  33445,  55555,
						62483,  77777,  79422,  85647,  93121};
	
}

What i don't understand is how come the binary_search isn't recognized inside the function. If i need to pass something to the function then what? Also it possibe to make the function above a template with the class vector inside the function already being a template, so that both templates work in unison, the function and the vector class template that was passed to the function?

Regardless of anything else, you can't initialize a vector like this, so the program won't compile anyway. Initialize the vector correctly so that the program compiles and see if you have better luck with the binary search.

0

Well all be damn. Its not in my book. Looks like i need to get a book on the STL to continue.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.