### C++: no matching function for call to 'min'

I have coded this program, but it returns the error: no matching function for call to 'min'.

I believe that I have declared the correct libraries and the only possibility of error is that there is a type error mismatch.

However, I don't know why an array and integer cannot be in a min function.

Thank you!

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 #include #include #include #include using namespace std; int main() { ifstream fin("test.in"); ofstream fout("test.out"); int k, n; fin >> k >> n; int data[10][20]; int data1[10][20]; int minimum[20]; int count = 0; for(int i = 0; i < k; i++) { for(int j = 0; j < n; j++) { fin >> data[i][j]; } } for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { data1[i][j] = data[j][i]; } } for(int i = 0; i < n; i++) { sort(data1[i], data1[i]+k); } for(int i = 0; i < n; i++) { minimum[i] = min(data1[i], data1[i]+k); } for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { if(minimum[i] > minimum[i+1]) { count++; } } } fout << count; }

Last edited on
std::min() returns the minimum value between two values. It doesn't take two iterators and give the minimum value in a sequence. If you want that function you'll have to code it yourself.
Remember to handle the case of an empty sequence.
Line 35: Since you sorted it previously it is always data1[i][0]

Line 39: What is this loop good for? You don't use j at all.
std::min_element() works with iterators
 12345678910111213141516171819202122 #include int main() { const int LIMIT{5}; int data[LIMIT]{4,3,5,1,2}; int minimum[LIMIT]{0}; int COUNT{0};for(int i = 0; i < LIMIT - 1; i++) { minimum[i] = std::min(data[i], data[i + 1]); std::cout << data[i] << '-' << data[i + 1] << " ->> " << minimum[i] << '\n'; COUNT++; } for(int i = 0; i < COUNT; i++) std::cout << minimum[i] << '\n'; return 0; }

 4-3 ->> 3 3-5 ->> 3 5-1 ->> 1 1-2 ->> 1 3 3 1 1 Program ended with exit code: 0
Topic archived. No new replies allowed.