且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将文件中的所有内容都转换为小写?

更新时间:2023-02-21 19:39:07

您可以使用std::tolower()函数="nofollow noreferrer">语言环境.不确定这是否是您要寻找的东西,但这是快速解决您的问题的方法(据我了解).

You can use the std::tolower() function from locale. Not sure if this is what you are looking for, but here is a quick solution to your problem (as i understand it).

#include<iostream>
#include<string>
#include<fstream>
#include<locale>

int main(){
  std::string input;
  std::ifstream inputStream;
  inputStream.open("input.txt", std::ifstream::in);


  while(inputStream >> input){
    for(auto s : input)
    {
      std::cout << std::tolower(s, std::locale());
    }
    std::cout << " ";
  }

  return 0;
}