📄 pr23016.cpp
字号:
////////////////////////////////////////
// File Name: pr23016.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 objects.
std::vector<int> intVector1;
std::vector<int> intVector2(5);
// Populate the vector.
intVector1.push_back(3);
intVector1.push_back(4);
intVector1.push_back(12);
intVector1.push_back(6);
intVector1.push_back(10);
// 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 the partial sum.
std::adjacent_difference(intVector1.begin(),
intVector1.end(), intVector2.begin());
// Display the contents of the resultant vector.
std::cout << "Contents of vector2: " << std::endl;
std::for_each(intVector2.begin(),
intVector2.end(), show_val);
std::cout << std::endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -