Created
August 16, 2017 04:42
-
-
Save dnaga392/e2af8bb6c1bcb92a69d853b222b55e9a to your computer and use it in GitHub Desktop.
(C++11) range-base for loop statement example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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