c++ - 找不到 toupper 并删除

标签 c++

所以,我一直在做 Reddit 的 daily programmer #140并且不能使用 std::toupper 和 std::erase。

包括:

#include <iostream>
#include <string>
#include <cctype>

部分与 toupper 和 erase(用于将单词转换为“CamelCase”):

std::string tekst;
std::cin >> tekst;    

tekst[0] = std::touppper(tekst[0]);
for(unsigned int i = 0; i < tekst.size(); i++){
    if(tekst[i] == 32){
        std::erase(tekst[i], 1);
        tekst[i] = std::toupper(tekst[i]);
    }
}

编译器显示错误:

error: 'touppper' is not a member of 'std'
error: 'erase' is not a member of 'std'

什么会导致它?提前致谢!

最佳答案

不是

std::touppper

但是

std::toupper

您需要将语言环境传递给函数,例如:http://www.cplusplus.com/reference/locale/toupper/

关于c++ - 找不到 toupper 并删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19882561/

相关文章:

c++ - 为什么角色在与他们打交道后会像 � 一样出现?

c++ - 使用 boost::make_shared 创建 vector 元素无法正常工作

c++ - 共享库对象文件链接

c++ - 如何将当前日期以数字形式放入 QLabel 中?

c++ - <错误 C2059 : syntax error : 'constant' > when compiling with const int

c++ - getline 的垃圾值

c++ - 有人可以解释 c++ FAILED 函数吗?

c++在对象组合上使用重载构造函数

c++ - Qt 不发射信号

c++ abort() 已在 rapidjson 上被调用