Advertisement
Infernale

NCTU LAB 24/10 NUM 2

Oct 24th, 2019
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct toUpper{
  7.   char operator()(char ch){
  8.     return ch - 32;
  9.   }
  10. };
  11.  
  12. void printStr(string str){
  13.   cout << str;
  14. }
  15.  
  16. int main(){
  17.   vector<string> data, functionResult, functorResult;
  18.   string temp;
  19.   while(cin >> temp){
  20.     data.push_back(temp);
  21.   }
  22.   for(auto it = data.begin(); it != data.end(); it++){
  23.     string str = *it;
  24.     transform(str.begin(), str.end(), str.begin(), ::toupper);
  25.     functionResult.push_back(str);
  26.   }
  27.   cout << "A)Function" << endl;
  28.   for_each(functionResult.begin(), functionResult.end(), printStr);
  29.   cout << endl;
  30.  
  31.   for(auto it = data.begin(); it != data.end(); it++){
  32.     string str = *it;
  33.     transform(str.begin(), str.end(), str.begin(), toUpper());
  34.     functorResult.push_back(str);
  35.   }
  36.   cout << "B)Functor" << endl;
  37.   for_each(functorResult.begin(), functorResult.end(), printStr);
  38.   cout << endl;
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement