Почему я продолжаю получать исключение Microsoft C++: std::out_of_range в ячейке памяти 0x000000B70C8FF360. при использоC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Почему я продолжаю получать исключение Microsoft C++: std::out_of_range в ячейке памяти 0x000000B70C8FF360. при использо

Сообщение Anonymous »


Visual studio shows 0 issues found but when program starts, a tab pop up with vector library and points on line 2151 and says

Unhandled exception at 0x00007FF90121CF19 in Project2.exe: Microsoft C++ exception: std::out_of_range at memory location I wrote a code that checks vector position (k) with next vector position (k + 1) and if it has the same number it removes position (k) It should stop checking and removing duplicates after it reaches size of vector but I keep getting the exception error. I tap continue and it works fine but still after every "continue" it shows an exception error. How to stop getting that?

void removeDuplicates(vector& nums) { int k = 0; while (k != nums.size() + 1) { vector::iterator iter = nums.begin() + k; if (nums.at(k) == nums.at(k + 1)) { nums.erase(iter); } ++k; } } I tried to tap continue and it works fine but still after every "continue" it shows an exception error. In code I tried to remove arithmetical operators next to "nums.begin()" and inside brackets of "nums.at()" but it didnt help.


Источник: https://stackoverflow.com/questions/780 ... mory-locat
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»