Debug Assertion Failed C/C++ Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

Debug Assertion Failed! Expression: vector subscript out of range

A debug-build STL check caught an out-of-range index.

Exact message you may see Debug Assertion Failedvector subscript out of rangeExpression: vector iterator not dereferencable
Seen on: C/C++ MSVC

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

  1. Check size() before indexing
  2. Use .at() to get an exception
  3. Fix iterator invalidation

Detailed fix by platform

C++

  1. if (i < v.size()) use(v[i]); or v.at(i)

How to diagnose

  1. Index — Value vs size()?
  2. Empty — Container empty?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

AddressSanitizer: heap-buffer-overflow — C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N (C/C++)AddressSanitizer: hea…C1010 — MSVC: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' (C/C++)C1010C1083 — MSVC: fatal error C1083: Cannot open include file: 'foo.h': No such file or directory (C/C++)C1083C1189 — MSVC: fatal error C1189: #error: ... (preprocessor error directive) (C/C++)C1189C2039 — MSVC: error C2039: 'x': is not a member of 'Y' (C/C++)C2039C2065 — MSVC: error C2065: 'x': undeclared identifier (C/C++)C2065C2259 — MSVC: error C2259: 'X': cannot instantiate abstract class (C/C++)C2259C2512 — MSVC: error C2512: 'X': no appropriate default constructor available (C/C++)C2512Debug Ass…

Explore the map of this error Full error map →

🧠 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.