Skip to content

Instantly share code, notes, and snippets.

@timofurrer
Created May 5, 2012 11:50
Show Gist options
  • Save timofurrer/2601832 to your computer and use it in GitHub Desktop.
Save timofurrer/2601832 to your computer and use it in GitHub Desktop.
range-based for loop in c++11
g++ -o for for.cpp -std=c++0x -Wall
g++ -o for for.cpp -std=c++0x
#include <iostream>
#include <vector>
int main( void )
{
std::vector<int> vec = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::cout << "The values of vec are:" << std::endl;
for( auto i : vec )
std::cout << i << std::endl;
for( auto &i : vec )
i *= 10;
std::cout << std::endl << "The values multiplied by 10 are:" << std::endl;
for( auto i : vec )
std::cout << i << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment