06_03 was modifiesd

This commit is contained in:
davoudn 2024-04-16 09:59:20 +03:30
parent a5f7685dcb
commit 23ff98814f
3 changed files with 8 additions and 6 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
// fig06_02.cpp
// Initializing an array in a declaration.
#include <format>
//#include <format>
#include <iostream>
#include <array>
@ -9,7 +9,7 @@ int main() {
// output each array element's value
for (size_t i{0}; i < values.size(); ++i) {
std::cout << std::format("{} ", values.at(i));
std::cout << values.at(i) << "\n";
}
std::cout << "\n\n";
@ -19,7 +19,7 @@ int main() {
// output each array element's value
for (size_t i{0}; i < values2.size(); ++i) {
std::cout << std::format("{} ", values2.at(i));
std::cout << values2[i] << "\n";
}
std::cout << "\n";

View File

@ -8,10 +8,14 @@ int main() {
std::array items2{1, 2, 3, 4, 5};
// display items before modification
for (int i{0}; i<items.size();i++)
std::cout << items[i] << "<-- items\n";
std::cout << "items before modification: ";
for (const int& item : items) { // item is a reference to a const int
std::cout << item << "<-- items\n";
}
}
std::cout << "items2 before modification:\n";
for (const int& item : items) { // item is a reference to a const int
std::cout << item << "<-- items2\n";
@ -38,8 +42,6 @@ int main() {
for (const int& item : items2) {
std::cout << item << "<-- items2\n";
}
// sum elements of items using range-based for with initialization
std::cout << "\n\ncalculating a running total of items' values:\n";
for (int runningTotal{0}; const int& item : items) {