複製鏈接
請複製以下鏈接發送給好友

transform

(函數命令)

鎖定
transform是一個函數命令,應用於指定範圍的每個元素。
外文名
transform
類    別
函數
來    源
標準庫
作    用
應用於指定範圍的每個元素

transform解釋

標準庫 <algorithm> 中的 transform

transform函數原型

transform [1]  函數原型如下:
template<class InputIterator,class OutputIterator,class UnaryOperator>
OutputIterator transform(InputIterator first1,InputIterator last1,OutputIterator result,UnaryOperatorop);
template<class InputIterator1,class InputIterator2,class OutputIterator,class BinaryOperator>OutputIterator transform(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,OutputIterator result,BinaryOperator binary_op);

transform函數説明

transform函數的作用是:將某操作應用於指定範圍的每個元素
//C++transform|C++tolower|C++toupper|C++字母轉大寫|C++字母轉小寫
#include <algorithm>
#include <cctype>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
string s("Welcome To WebSite!");
cout << s << endl;
transform(s.begin(), s.end(), s.begin(), ::tolower); //字母轉小寫
cout << s << endl;
transform(s.begin(), s.end(), s.begin(), ::toupper); //字母轉大寫
cout << s << endl;
return 0;
}
參考資料