bool for no duplicates

I'm trying to make a simple bool function that can check if there are any duplicates in a string array. below is what i wrote but shows abort()has been called error message when there are duplicates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool noDup(const string arr[], int n) {		//need to be fixed
	bool result = true;

	if (n < 0) result = false;
	else if (n == 0) result = true;
	else {
		for (size_t i=0; i < n; i++) {
			for (size_t k = 0; k < n; k++) {
				if (i!=k && arr[i] == arr[k]) result = false;
			}
		}
	}
	return result;
}


what would be the reason?
what would be the reason?

At a guess, n is exceeds the capacity of the array fed to the function. The problem is not in the code you've shown.
Topic archived. No new replies allowed.