📄 pr23013.cpp
字号:
////////////////////////////////////////
// File Name: pr23013.cpp
////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
////////////////////////////////////////
// The function to be called by
// for_each().
////////////////////////////////////////
void show_val(int val)
{
std::cout << val << std::endl;
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// Create the vector object.
std::vector<int> intVector1;
// Populate the vector.
for (int x=0; x<5; ++x)
intVector1.push_back(x);
// Display the contents of the vector.
std::cout << "Contents of vector1: " << std::endl;
std::for_each(intVector1.begin(),
intVector1.end(), show_val);
std::cout << std::endl;
// Calculate and display sum.
int result = std::accumulate(intVector1.begin(),
intVector1.end(), 5);
std::cout << "Result = " << result;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -