[ create a new paste ] login | about

Link: http://codepad.org/R1Vrwjpt    [ raw code | output | fork ]

fisherro - C++, pasted on Feb 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <cctype>
#include <algorithm>
#include <functional>
#include <iostream>
 
int main()
{
    //Transform a string in-place
    std::string s("hello");
    std::transform(s.begin(), s.end(), s.begin(), std::ptr_fun<int, int>(std::toupper));
    std::cout << s << std::endl;

    //Transform a string while copying
    std::string s2;
    s2.reserve(s.size());
    std::transform(s.begin(), s.end(), std::back_inserter(s2), std::ptr_fun<int, int>(std::tolower));
    std::cout << s2 << std::endl;
}


Output:
1
2
HELLO
hello


Create a new paste based on this one


Comments: