Debug Assertion Failed! Expression: vector subscript out of range
A debug-build STL check caught an out-of-range index.
Debug Assertion Failedvector subscript out of rangeExpression: vector iterator not dereferencable Meaning
MSVC's debug iterators and checked operator[] abort with a dialog naming the expression. Release builds do not check, and read garbage or crash instead.
Common causes
- Index equal to or beyond
size() - Empty vector indexed with
[0] - Iterator from another container or invalidated
- Signed/unsigned index underflow
⚡ Quick fix
- Check
size()before indexing - Use
.at()to get an exception - Fix iterator invalidation
Detailed fix by platform
C++
if (i < v.size()) use(v[i]);orv.at(i)
How to diagnose
- Index — Value vs size()?
- Empty — Container empty?
- Iterator — Invalidated?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- C1010 MSVC: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"'
- C1083 MSVC: fatal error C1083: Cannot open include file: 'foo.h': No such file or directory
Most viewed in C/C++
- Bus error C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- was not declared in this scope C++: error: 'x' was not declared in this scope (undeclared identifier)
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 2 Dec 2026