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

📄 val1.cpp

📁 stl自带源码
💻 CPP
字号:
/* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */#include <iostream>#include <valarray>using namespace std;// print valarraytemplate <class T>void printValarray (const valarray<T>& va){    for (int i=0; i<va.size(); i++) {        cout << va[i] << ' ';    }    cout << endl;}int main(){    // define two valarrays with ten elements    valarray<double> va1(10), va2(10);    // assign values 0.0, 1.1, up to 9.9 to the first valarray    for (int i=0; i<10; i++) {        va1[i] = i * 1.1;    }    // assign -1 to all elements of the second valarray    va2 = -1;    // print both valarrays    printValarray(va1);    printValarray(va2);    // print minimum, maximum, and sum of the first valarray    cout << "min(): " << va1.min() << endl;    cout << "max(): " << va1.max() << endl;    cout << "sum(): " << va1.sum() << endl;    // assign values of the first to the second valarray    va2 = va1;    // remove all elements of the first valarray    va1.resize(0);    // print both valarrays again    printValarray(va1);    printValarray(va2);}

⌨️ 快捷键说明

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