Skip to content

Instantly share code, notes, and snippets.

@dnaga392
Created August 16, 2017 04:42
Show Gist options
  • Save dnaga392/e2af8bb6c1bcb92a69d853b222b55e9a to your computer and use it in GitHub Desktop.
Save dnaga392/e2af8bb6c1bcb92a69d853b222b55e9a to your computer and use it in GitHub Desktop.
(C++11) range-base for loop statement example.
#include <iostream>
#include <vector>
int range_base_for_loop()
{
std::vector<int> integers{2, 3, 5, 7, 13};
for (auto&& x : integers)
{
std::cout << "x = " << x << std::endl;
x += 1;
}
for (const auto& x : integers)
{
std::cout << "x = " << x << std::endl;
// x += 1; // error: assignment of read-only reference 'x'
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment