简体   繁体   English

调试错误。 R6010中止已被调用()

[英]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. 我在少数地方尝试了cout <<,看来问题开始于while循环的开始。

You try to access the first element of rep , which is an empty vector. 您尝试访问rep的第一个元素,它是一个空向量。

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. 现在,您正在读取和写入不是您自己的内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM