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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:26+00:00 2026-05-27T17:27:26+00:00

From the c++0x Wikipedia site: int my_array[5] = {1, 2, 3, 4, 5}; for

  • 0

From the c++0x Wikipedia site:

int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array) {
    x *= 2;
}

So why does this code not work?

int main(int argc, char* argv[])
{
    for (char *arg : argv)
    {
        // Do something.
    }
}

Error:

main.cpp:36: error: no matching function for call to ‘begin(char**&)’

I am using Qt with g++ 4.6.1 on Ubuntu 11.10.

Additional Information

Is There a Range Class in C++0x

Range-Based For-Loop Statement Definition Redundance

  • 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-27T17:27:27+00:00Added an answer on May 27, 2026 at 5:27 pm

    You don’t, because the system can’t tell how long argv is at compile time. Someone can likely find the proper section of the standard to quote you about this.

    There is a way around it though, and that’s to create a custom class to wrap argv. It’s not even that hard.

    class argv_range {
     public:
       argv_range(int argc, const char * const argv[])
            : argc_(argc), argv_(argv)
       {
       }
    
       const char * const *begin() const { return argv_; }
       const char * const *end() const { return argv_ + argc_; }
    
     private:
       const int argc_;
       const char * const *argv_;
    };
    

    Here’s how you use it:

    for (const char *arg: argv_range(argc, argv)) {
       // Do something.
    }
    

    Yeah, I use a lot of consts. Basically, argv is an array of character pointers, none of which should be modified, each pointing to a string, none of the characters of which should be modified either.

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

Sidebar

Related Questions

I regularly extract tables from Wikipedia. Excel's web import does not work properly for
http://en.wikipedia.org/wiki/All_nearest_smaller_values . This is the site of the problem and here is my code,
This is a code that I got from the site here and I'd like
Here is a little snippet of code from Wikipedia's article on malloc(): int *ptr;
Quote from Wikipedia : A public key token. This is a 64-bit hash of
I got the code from wikipedia for linked list ( http://en.wikipedia.org/wiki/Linked_list ). But it
I'm using wikitools package to parse the wikipedia. I just copy this example from
I'm extracting a string from wikipedia API that initially looks like this: link text
I had spend some time on this Bridge pattern example from wikipedia , however,
this is basically what I'm doing. I select a science article from en.wikipedia.org 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.