Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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 << '
';
    for (auto ord : ordinals) {
       std::cout << ord << ' ';
    }
    std::cout << '
';
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Pawri Meme codechef solution in c++ 
Cpp :: template design pattern 
Cpp :: break input stream into words 
Cpp :: what are manipulators in c++ 
Cpp :: C++ operation 
Cpp :: C++ Booleans 
Cpp :: C++ Display Numbers from 1 to 5 
Cpp :: 378. Kth Smallest Element in a Sorted Matrix using binary search 
Cpp :: no argument but return value in c++ 
Cpp :: cpp-variadics/problem? 
Cpp :: Define and show the implementation of the functions of an arrayList. 
Cpp :: niet full form 
Cpp :: time optimisation c++ 
Cpp :: Int main ( ) { int i,n; cinn; i=n; while(i=1) { i=i+5; i=i-6; } } 
Cpp :: sprintf add two xeroes for a float number 
Cpp :: windows install cppcheck 
Cpp :: C++ Point to Every Array Elements 
Cpp :: The program must enter a natural number n from the console and find the number previous to n that is not divisible by 2 , 3 and 5 . 
Cpp :: sort sub vector, sort range of vector c++ 
Cpp :: c++ Is there still a need to provide default constructors to use STL containers 
Cpp :: hello command not printing in c++ 
Cpp :: c++ ascii value 
Cpp :: search in vector of pairs c++ 
Cpp :: return function in cpp 
Cpp :: in c++ 
Cpp :: print all even number using for loop c++ 
Cpp :: dateformat in flutter 
C :: plt hide axis ticks 
C :: Invalid public key for CUDA apt repository 
C :: dvlprroshan 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =