简体   繁体   中英

C++ Debug Assertion Failed - vector subscript out of range on visual studio

My code

while (board[x + 1][y] == '#' && x + 1 < m) x++;

This part is causing an error on Visual Studio . But, this code is working on web site for coding-test.


vector board size is 4x5.

An error occurs at x=1, y=3.

Here is a board status.

[0] # # # A A
[1] # # # A A
[2] # # # # A
[3] # # # A A 

Error occurs when conditions are true.

What is a problem?

As in my comment:

while (x + 1 < m && board[x + 1][y] == '#' ) x++;

if the first logical expression is false, then (because we AND them) the second one is not evaluated and the array is not read out of the bounds.

It does not have anything in common with Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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