How to compare vector digits

Hello. I am creating a bool function that returns whether an integer in a vector is greater than the second integer, but I don't know how to compare them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;

bool sort(vector<int>);

int main()
{




	cin.get();
	return 0;
}

bool sort(vector<int> numbers)
{
	return numbers < // how do I compare the second number?
}
Last edited on
Hello TheDomesticUser2,

You have included the "string" header file, but never use a string.

You do use a vector, but need to include the header file for vectors.

Do yo want to sort the vector or compare two numbers of the vector? You should consider changing the name to something that better describes what the function does.

I think this is closer to what you want to do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
#include <vector>  // <--- Added. Need to include this header file to use vectors.

//using namespace std;  // <--- Best not to use.

bool checkNumbers(int num1, int num2);

int main()
{
	std::vector<int> numbers{ 2, 20, 15, 20, 5 };

	for (size_t lc = 0; lc < numbers.size()-1; lc++)
	{
		if (checkNumbers(numbers[lc], numbers[lc + 1]))
			std::cout << "\n First number greater than second\n" << std::endl;
		else
			std::cout << "\n First number less than second\n" << std::endl;
	}


	std::cin.get();

	return 0;
}

bool checkNumbers(int num1, int num2)
{
	return num1 > num2; // how do I compare the second number?
}


Hope that helps,

Andy
Topic archived. No new replies allowed.