Skip to content

Instantly share code, notes, and snippets.

@spencerdeinum
Created December 30, 2013 19:41
Show Gist options
  • Save spencerdeinum/8187000 to your computer and use it in GitHub Desktop.
Save spencerdeinum/8187000 to your computer and use it in GitHub Desktop.
c++ iteration
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
std::vector<int> vec = { 1, 2, 3, 4, 5 };
std::cout << "For loop, with auto" << std::endl;
for(auto iter = vec.begin(); iter != vec.end(); ++iter)
{
std::cout << *iter << std::endl;
}
std::cout << "For loop, with range" << std::endl;
for(auto i: vec)
{
std::cout << i << std::endl;
}
std::cout << "for_each, with lambda" << std::endl;
for_each(vec.begin(), vec.end(), [](int i) {
std::cout << i << std::endl;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment