Thread: Range-based for loops in C++11

  1. #1
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012

    Range-based for loops in C++11

    Hi guys, just wanted to let everyone know about a new article I've posted to the site, discussing Range-Based for Loops in C++11

    This is part of a larger series I've been working on, covering the different elements of the new C++ standard, C++11 (formerly known as C++0x).

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    These guys do a fair job of keeping up with the GCC built with MinGW as a target.

    You know, for anyone who wants to give it a try without the hassle of mutilating your system with a botched "CygWin" install.

    Soma

    Fortran, C, C++ for Windows
    MinGW-w64 - for 32 and 64 bit Windows - Browse /Toolchains targetting Win32 at SourceForge.net

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Visual Studio has had them since 2008, they use the CLI syntax though. Portable code be damned!
    Code:
    #include <iostream>
    int main()
    {
       int array[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
       for each(int a in array)
       {
           std::cout << a << ' ';
       }
       std::cout << std::endl;
    }

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Saw this bit of code in the following link and here as well. Shouldn't the cout line reference the auto variable address_entry and not address_book?

    Range-based for loops in C++11-untitled2-jpg

    Range-based for loops in C++11-untitled-jpg
    Last edited by hk_mp5kpdw; 09-12-2011 at 01:41 PM. Reason: Added second pic/link
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    @phantomotap Thanks for the pointer; I added a link to the SourceForge page from the article. Good to know about!

    @adeyblue I think I'll stick with standard C++

    @hk_mp5kpdw Oops, thanks! I've fixed that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. range based for command
    By tabl3six in forum C++ Programming
    Replies: 19
    Last Post: 08-09-2011, 07:14 AM
  2. Replies: 3
    Last Post: 06-01-2011, 04:19 PM
  3. Reversing the traversal of c++0x's range based for
    By Mozza314 in forum C++ Programming
    Replies: 29
    Last Post: 03-15-2011, 06:11 PM
  4. loops, menu loops
    By gloworm in forum C Programming
    Replies: 17
    Last Post: 04-12-2010, 07:59 PM
  5. Range
    By volk in forum C Programming
    Replies: 3
    Last Post: 12-19-2002, 09:43 AM