Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:26:09+00:00 2026-05-31T13:26:09+00:00

This feels like a newbie issue, but I can’t seem to figure it out.

  • 0

This feels like a newbie issue, but I can’t seem to figure it out. I want to iterate over the items in a std::vector. Currently I use this loop:

for (unsigned int i = 0; i < buffer.size(); i++) {
    myclass* var = buffer.at(i);
    [...]
}

However, I realised that I actually want to iterate over it in the opposite order: starting at the end and working my way to 0. So I tried using this iterator:

for (unsigned int i = buffer.size()-1; i >= 0; i--) {
    myclass* var = buffer.at(i);
    [...]
}

But by simply replacing the old line with the new (and of course, recompiling), then it goes from running properly and iterating over the code, it instead causes the program to crash the first time it hits this line, with this error:

http://i43.tinypic.com/20sinlw.png

Followed by a “[Program] has stopped working” dialog box.

The program also returns exit code 3, according to Code::Blocks, which (if this article is to be believed) means ERROR_PATH_NOT_FOUND: The system cannot find the file specified.

Any advice? Am I just missing something in my for loop that’s maybe causing some sort of memory issue? Is the return code of 3, or the article, misleading, and it doesn’t actually mean “path not found”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:26:09+00:00Added an answer on May 31, 2026 at 1:26 pm

    When i == 0 (i.e. what should be the last iteration), the decrement i-- causes i to wrap around to the largest possible value for an unsigned int. Thus, the condition i >= 0 still holds, even though you’d like the loop to stop.

    To fix this, you can try something like this, which maintains the original loop logic, but yields a decrementing i:

    unsigned int i;
    unsigned int size = buffer.size();
    for (unsigned int j = 0; j < size; j++) {
        i = size - j - 1;
    

    Alternatively, since std::vector has rbegin and rend methods defined, you can use iterators:

    for(typename std::vector<myclass *>::reverse_iterator i = buffer.rbegin(); i != rend(); ++i)
    {
        myclass* var = *i;
        // ...
    }
    

    (There might be small syntactic errors – I don’t have a compiler handy)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This feels like a really basic question, but I can't figure it out anyway..
This feels like a stupid question, but I can't seem to see the answer.
This feels like a really simple question, but I can't find the answer anywhere.
This feels like a beginner question with a pretty obvious answer, but I can't
This feels like it should be really easy, but I just can't get it
This feels like it should be pretty simple, but not much seems to be
This feels like the kind of code that only fails in-situ, but I will
OK, this feels like an idiot question, but I'm stuck - I don't know
It feels like there must be some semi-simple solution to this, but I just
My string looks like this $string_value = /hello/world/this/feels/great/ how can I trim world and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.