Horje
c++ copy with transform Code Example
c++ copy with transform
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
 
int main()
{
    std::string s("hello");
    std::transform(s.begin(), s.end(), s.begin(),
                   [](unsigned char c) -> unsigned char { return std::toupper(c); });
 
    std::vector<std::size_t> ordinals;
    std::transform(s.begin(), s.end(), std::back_inserter(ordinals),
                   [](unsigned char c) -> std::size_t { return c; });
 
    std::cout << s << ':';
    for (auto ord : ordinals) {
       std::cout << ' ' << ord;
    }
 
    std::transform(ordinals.cbegin(), ordinals.cend(), ordinals.cbegin(),
                   ordinals.begin(), std::plus<>{});
 
    std::cout << '\n';
    for (auto ord : ordinals) {
       std::cout << ord << ' ';
    }
    std::cout << '\n';
}




Cpp

Related
hamming c++ Code Example hamming c++ Code Example
error C2011 Code Example error C2011 Code Example
why constructor can't be static in c++ Code Example why constructor can't be static in c++ Code Example
c++ vector declaration Code Example c++ vector declaration Code Example
c++ rand Code Example c++ rand Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7