How do I lowercase std::string?

Asked 2 years ago, Updated 2 years ago, 119 views

How do I lowercase std::string?

Is there any other way besides my sauce? This looks so messy

char upperToLower(char in){
  if(in<='Z' && in>='A')
    return in-('Z'-'z');
  return in;
}

...

std::transform(data.begin(), data.end(), data.begin(), ::upperToLower);

string c++ c++standard-library

2022-09-21 17:52

1 Answers

Write the toolower() provided by c++

#include <algorithm>
#include <string> 

std::string data = "HELLO C WORLD"; 
std::transform(data.begin(), data.end(), data.begin(), ::tolower);

You can use it with .


2022-09-21 17:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.