⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex10_12.cpp

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 CPP
字号:
// Ex10_12.cpp
// Using stream and inserter iterators
#include <iostream>
#include <numeric>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::istream_iterator;
using std::ostream_iterator;
using std::back_inserter;
using std::accumulate;


int main()
{
  vector<int> numbers;
  cout << "Enter a series of integers separated by spaces" 
       << " followed by Ctrl+Z or a letter:" << endl;

  istream_iterator<int> input(cin), input_end;
  ostream_iterator<int> out(cout, " ");

  copy(input, input_end, back_inserter<vector<int>>(numbers));

  cout << "You entered the following values:" << endl;
  copy(numbers.begin(), numbers.end(), out);

  cout << endl << "The sum of these values is " 
       << accumulate(numbers.begin(), numbers.end(), 0) << endl;

  return 0;
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -