mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 12:44:40 +03:00
23 lines
588 B
C++
23 lines
588 B
C++
//
|
|
// 2.11.for.loop.cpp
|
|
// chapter 2 language usability
|
|
// modern cpp tutorial
|
|
//
|
|
// created by changkun at changkun.de
|
|
//
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
int main() {
|
|
std::vector<int> vec = {1, 2, 3, 4};
|
|
if (auto itr = std::find(vec.begin(), vec.end(), 3); itr != vec.end()) *itr = 4;
|
|
for (auto element : vec)
|
|
std::cout << element << std::endl; // read only
|
|
for (auto &element : vec) {
|
|
element += 1; // writeable
|
|
}
|
|
for (auto element : vec)
|
|
std::cout << element << std::endl; // read only
|
|
} |