Range based for loops

Can anybody explain Range based for loops ?
I typed 'C++ range based for loop' into google and this was the first link:

http://www.cprogramming.com/c++11/c++11-ranged-for-loop.html

It explains it in detail.
Last edited on
I am studying C++ from this site and I havent studied arrays, STL, vector and all that stuff . Obviously I visited that link but it was of no use for me .
Did you check the tutorial on this site? Scroll down this page for the range based for loop info.

http://www.cplusplus.com/doc/tutorial/control/
Range-based for loops are used to iterate over each element in a container such as an array, vector, list, etc.
Last edited on
In this syntax
// range-based for loop
#include <iostream>
#include <string>
using namespace std;

int main ()
{
string str {"Hello!"};
for (char c : str)
{
std::cout << "[" << c << "]";
}
std::cout << '\n';
}
WHY IS STD::COUT USED WHEN USING NAMESPACE STD DECLARATION IS ALREADY MENTIONED BEFORE INT MAIN ? ()
It wouldn't be necessary. Maybe the person writing that section is accustomed to using the std:: prefix where necessary instead of pulling the whole standard namespace into programs?
It's a bit inconsistent compared to the rest of the tutorial code.
Topic archived. No new replies allowed.