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 9013095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:10:14+00:00 2026-06-16T03:10:14+00:00

Example: for (vector<string>::reverse_iterator it = myV.rbegin(); it != myV.rend(); ++it) { cout << current

  • 0

Example:

for (vector<string>::reverse_iterator it = myV.rbegin(); it != myV.rend(); ++it)
{
  cout << "current value is: " << *it << ", and current position is: " << /*  */ << endl;
}

I know I could check how many items there are in the vector, make a counter, and so on. But I wonder if there is a more direct way of checking current index without asserting that I got the length of the vector right.

  • 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-06-16T03:10:16+00:00Added an answer on June 16, 2026 at 3:10 am

    vector Iterators support difference you can subtract you current iterator it from rbegin.


    EDIT

    As noted in a comment not all iterators support operator- so std::distance would have to be used. However I would not recommend this as std::distance will cause a liner time performance cost for iterators that are not random access while if you use it - begin() the compiler will tell you that won’t work and then you can use distance if you must.

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

Sidebar

Related Questions

vector<vector<string> > test for example. g++, you can do test.reserve(10); test[0] = othervector; test[9]
Please take a look at this example: #include <iostream> #include <vector> #include <string> using
I'm wondering if it's possible if you have, for example, a vector<string> and a
For example: std::vector<std::pair<std::string, bool > > v; std::pair<std::string, bool> pr; v.push_back( pr ); Assuming
I came across this example from Accelerated C++ vector<string> func(const string&); //function declaration vector<string>
Please consider the following example: #include <string> #include <vector> using std::string; using std::vector; template
For example I have a vector in my c++ program: vector<string> files; And this
Consider this example: #include <iostream> #include <string> #include <vector> #include <iterator> int main() {
Compiling this example #include <boost/bind.hpp> #include <boost/algorithm/string.hpp> #include <algorithm> #include <iostream> #include <vector> using
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;

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.