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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:07:03+00:00 2026-05-27T15:07:03+00:00

I have an std::vector, let’s say of integers for simplicity. std::vector<int> ivec; ivec.push_back(1); ivec.push_back(2);

  • 0

I have an std::vector, let’s say of integers for simplicity.

std::vector<int> ivec;
ivec.push_back(1);
ivec.push_back(2);
... //omitting some push back's 3 to 99
ivec.push_back(100);

The standard way to iterate is known

std::map<int>::iterator it;
for( it = ivec.begin(); it != ivec.end(); it++ ) 
  print();

That iteration will print 1,2,3, … 100.

I want to traverse all vector elements starting from a predefined index and not from it.begin().
I would like to print

3,4,5,6 … 99, 100, 1, 2

Can you share your thoughts here?

It might ok to do it in two steps

for( it = ivec.begin()+index; it != ivec.end(); it++ ) and then (if index !=0)

for ( it = ivec.begin; it = it = ivec.begin() + (index-1); it++)
  • 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-27T15:07:04+00:00Added an answer on May 27, 2026 at 3:07 pm
    bool wrapped = false;
    for (auto it = vec.begin() + index; (it != vec.begin() + index) || !wrapped; ++it)
    {
        if (it == vec.end())
        {
            it = vec.begin();
            wrapped = true;
        }
        std::cout << *it;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a std::vector and I get by some means the address
Let's say I have a function: typedef std::vector<int> VecType; VecType randomVector(); int processing() {
I have two containers, let's say they're defined like this: std::vector<std::unique_ptr<int>> a; std::vector<std::unique_ptr<int>> b;
Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();
Let's we have std::vector <std::vector <unsigned short int>> face; face.resize(nElm); Its OK to resize()
Let's say I have a: std::vector<std::list<Node> > And let's say Node is: class Node
Let's say I have a class FOO. I want to have a std::vector of
Suppose i have a std::vector<int> v //and ... for(int i =0;i<100;++i) v.push_back(i); now i
let's say i want to have a member variable for a pointer to std::vector

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.