Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iterator>
  5.  
  6. template <class T>
  7. void print(const T& v) {
  8. std::copy(v.begin(), v.end(),
  9. std::ostream_iterator<typename T::value_type>(std::cout, "n"));
  10. }
  11.  
  12. std::string lowercase(const std::string& s)
  13. {
  14. std::string result(s);
  15. std::transform(result.begin(), result.end(), result.begin(), ::tolower);
  16. return result;
  17. }
  18.  
  19. int main() {
  20.  
  21. std::vector<std::string> tokens {"Col1", "Col2", "File", "FileIn.dat", "Out", "FileOut.dat"};
  22. std::transform(tokens.begin(), tokens.end(), tokens.begin(), lowercase);
  23.  
  24. // how to replace lowercase() with a lambda that will take the previous
  25. // element into account while converting an element into lowercase
  26. print(tokens);
  27.  
  28. return 0;
  29. }
  30.  
  31. {"col1", "col2", "file", "FileIn.dat", "out", "FileOut.dat"};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement