📄 chapter11-30.cpp
字号:
//文件名:CHAPTER11-30.cpp
#pragma warning (disable : 4786)
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
#include <string>
using namespace std;
typedef vector < float > FloatArray;
typedef vector < string > StringArray;
typedef ostream_iterator <float, char, char_traits <char> > FloatOstreamIt;
void main ()
{
FloatArray rgFA; // a vector of floats
FloatOstreamIt OstreamIt(cout," ");
for (int i=0; i<10; i++) rgFA.push_back(1.0f/(i+1));
copy(rgFA.begin(),rgFA.end(),OstreamIt);
cout << endl;
cout << "The sum of 1 + 1/2 + 1/3 + ... + 1/10 is "<< accumulate(rgFA.begin(),rgFA.end(),0.0f) << endl;
cout << "The product of 1 * 1/2 * 1/3 * ... * 1/10 is "
<< accumulate(rgFA.begin(),rgFA.end(),1.0f,multiplies<float>())<< endl;
// Initialize array of strings
StringArray rgs;
rgs.push_back("This ");
rgs.push_back("is ");
rgs.push_back("one ");
rgs.push_back("sentence. ");
cout << "The concatenated vector of strings: " << accumulate(rgs.begin(),rgs.end(),string(""));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -