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

📄 37-2.cpp

📁 effective stl 源代码 code
💻 CPP
字号:
//
// More from ESTL Item 37
//

#include <list>
#include <iostream>
#include <numeric>
#include <string>
#include "ESTLUtil.h"
using namespace std;

string::size_type									// see below for info
stringLengthSum(string::size_type sumSoFar,			// on string::size_type 
					const string& s)
{
	return sumSoFar + s.size();
}

int main()
{
	using namespace std;
	using namespace ESTLUtils;

	const int vals[] = { 1, 2, 3, 4, 5};
	const int nvals = sizeof vals / sizeof(int);

	cout << "Enter some integer values separated by spaces, control-Z to quit: " << endl;

	cout << "The sum of the ints on the standard input is "		// print the sum of
		<< accumulate(		istream_iterator<int>(cin),			// the ints in cin
				istream_iterator<int>(), 0) << endl;
	
	string s1("this is a");
	string s2("test of the");
	string s3("emergency broadcast system");

	string::size_type sum = 0;
	sum = stringLengthSum(sum, s1);
	sum = stringLengthSum(sum, s2);
	sum = stringLengthSum(sum, s3);

	cout << "sum of lengths = " << sum << endl;
	
	return 0;
}

⌨️ 快捷键说明

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