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

📄 tchapter11-32.cpp

📁 C++STL程序员开发指南
💻 CPP
字号:
//文件名:CHAPTER11-32.cpp
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
using namespace std;
typedef vector < float > FloatArray;
typedef ostream_iterator < float, char, char_traits<char> >
FloatOstreamIt;
void main ()
{
    FloatOstreamIt itOstream(cout," ");
    FloatArray rgF1, rgF2;    // Initialize the arrays
    for (int i=1; i<=5; i++) {        rgF1.push_back(i);        rgF2.push_back(i*i);    };
    cout << "Array 1: ";     // Print the arrays
    copy(rgF1.begin(),rgF1.end(),itOstream);
    cout << endl << "Array 2: ";
    copy(rgF2.begin(),rgF2.end(),itOstream);
    cout << endl;
    // Compute the inner_product of the arrays.  This is the
    // sum of the products (S.O.P) of the corresponding elements
    float ip1 = inner_product(rgF1.begin(),rgF1.end(),rgF2.begin(),0);
    cout << "The inner product (S.O.P) of Array1 and Array2 is " << ip1 << endl;
    // Compute the inner_product of the arrays.  This is the
    // product of the sums (P.O.S.) of the corresponding elements
    float ip2 = inner_product(rgF1.begin(),rgF1.end(),rgF2.begin(),1,
 multiplies<float>(),plus<float>());
    cout << "The inner product (P.O.S.) of Array1 and Array2 is " << ip2 << endl;
}

⌨️ 快捷键说明

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