几种字符串字母大小写转换方法

  1. 使用c++
#include <algorithm>
#include <string>
std::string str = "Hello World";
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
  1. 使用boost库
#include <boost/algorithm/string.hpp>
#include <string>

std::string str = "Hello World";

boost::to_upper(str);

std::string newstr = boost::to_upper_copy<std::string>("Hello World");
  1. c++11循环处理
for (auto & c: str) c = toupper(c);

猜你喜欢

转载自blog.csdn.net/wuquan_1230/article/details/125790087