Archive for 10 November 2014

C++11 range-based for loops

Great link: Range-based for loop

Nowadays, almost every programming language has a convenient way to write a for loop over a range of values. Finally, C++ 11 has the same concept; this is a long awaited C++ feature.

Here’s an example:


vector<string> vec;
vec.push_back( "hello" );
vec.push_back( "world" );

for (string s : vec )
{
cout << s;
}