Luka
Luka

Reputation: 143

Debug error. R6010 abort has been called()

#include "../../../std_lib_facilities.h"

int main() {

vector <int> nmb; vector <int> rep; vector <int> prt; int flag = 0; int temp = 0; int br = 0; int max = -1; int ind = 0; cout << "Enter as much integers as you like\n"; while (cin >> temp) { if (nmb.size() == 0) { nmb.push_back(temp); prt.push_back(temp); ++rep[br]; ++br; } else { for (int i = 0; i < nmb.size(); ++i) { if (temp == nmb[i]) { ++rep[i]; flag = 1; } } if (flag == 0) { nmb.push_back(temp); prt.push_back(temp); ++rep[br]; ++br; } else if (flag == 1) { flag = 0; prt.push_back(temp); } } } cout << "You've entered numbers\n"; for (int j = 0; j < prt.size(); ++j) cout << prt[j] << " "; for (int k = 0; k < rep.size(); ++k) if (rep[k] > max) { max = rep[k]; ind = k; } cout << "\n\nMost repeated number is " << nmb[ind] << endl;}

My task is to write what number has been entered max times. I know it's probably not the best idea but it was the first "good" one I had so I went with it. It compiles fine but gives me that error from that title when running. I tried cout << in few places and it seems that problem starts at the beginning of while loop.

Upvotes: 0

Views: 4876

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385108

You try to access the first element of rep, which is an empty vector.

You have to actually add elements before you may access them. Right now you're reading from and writing to memory that is not yours.

Upvotes: 1

Related Questions