/*
(C) OOMusou 2006 http://oomusou.cnblogs.com
Filename : StreamIteratorCinCout.cpp
Compiler : Visual C++ 8.0 / ISO C++
Description : Demo how to use transform() algorithm
Release : 12/10/2006
*/
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
string& toLower(string&);
/*
transform(s.begin(),s.end(),//source
s.begin(),//destination
tolower);//operation
*/
int main()
{
vector<string> svec;
svec.push_back("Stanley B. Lippman");
svec.push_back("Scott Meyers");
svec.push_back("Nicolai M. Josuttis");
// Modify each string element
transform(svec.begin(), svec.end(), svec.begin(), toLower);
copy(svec.begin(),svec.end(), ostream_iterator<string>(cout,"\n"));
return 0;
}
string& toLower(string& s)
{
// Modify each char element
transform(s.begin(), s.end(), s.begin(), ::tolower);
//C中的ctype.h也有一个tolower和C++模板库中的相冲突,故要加上域名限定符
return s;
}