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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:32:33+00:00 2026-06-06T22:32:33+00:00

I have a piece of code that was written by someone else before the

  • 0

I have a piece of code that was written by someone else before the New ISO come into effect.

The for LOOP in for (pa=a.begin(), i=0; pa != a.end(); ++pa) has a little trouble executing because of the i=0 part of the syntax. Also, I had to prefix the other for loop syntaxes to read for ( int i .....) with the int before the i. However, I don’t know how to fix the int i=0 in this line: for (pa=a.begin ( ), i=0; pa != a.end ( ); ++pa). Please help me out.

  for ( int i = 0; pa != a.end(); ++pa)
      *pa = ++i;

  for (int i=0; i<10; i++)
      std::cout << "a[" << i << "]=" << a[i] << std::endl;

  // int i;  // note that this will work, but I do not want this extra line.

  for (pa=a.begin(), i=0; pa != a.end(); ++pa)
      std::cout << "a[" << i++ << "]=" << *pa << std::endl;
  • 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-06T22:32:34+00:00Added an answer on June 6, 2026 at 10:32 pm

    An extra declaration outside the for loop is the only sensible way to have two iteration variables of unrelated types in C++98 and later versions of the language. The initialiser can either be a single expression or a single declaration, and a declaration can’t declare variables of multiple unrelated types.

    If you really want a one-liner in this situation, then you could use this monstrosity:

    for (int i = ((pa = a.begin()), 0); pa != a.end(); ++pa, ++i)
    

    If you do that sort of thing regularly, then make sure that no-one who maintains your code knows where you live.

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

Sidebar

Related Questions

I have a piece of code that the ARC converter turned into this... //
I have written this piece of code that splits a string and stores it
In jQuery, I have written a piece of code that appears on every page
I have written the following piece of code that reads through a given xml-file
I have written a piece of code in C#. That is, dynamically adding TextBox
I have a piece of code that is written in C++ and need it
I have written a piece of code by mistake that works. Now i need
I have a piece of code that I've haphazardly written in order to run
I have written a small piece of code that would perform Run length encoding
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();

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.