让数组与toupper一起工作
Getting Arrays to work with toupper
由于某种原因,我一直收到一个错误,上面写着"toupper不能用作函数"。但对我来说,understanding toupper是一个全局函数,它可以将小写字符转换为大写字符。
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string input;
string output;
int toupper;
cout<<"Enter a String of Charchters to be Capitalized : ";
cin>>input;
string arrayinput[20]= input;
output = toupper(arrayinput);
cout<<"nnn"<<output<<"nnn";
cout<<"Press <Enter> to Exit";
cin.ignore();
cin.get();
return 0;
}
您已经创建了一个名为int toupper
的局部变量-将该变量重命名为其他变量。
编辑以添加:问题不止于此。input
是字符串;您想要迭代该字符串的长度,并使用string::at(i)
在每个位置获得char*
。然后使用atoi
将char转换为int,这是toupper
作为参数的类型。
如果您想对字符串数组执行此操作,那么在修复变量名问题后,在循环中使用std::transform
:
for (auto& str : arrayinput)
std::transform(std::begin(str), std::end(str), std::begin(str), ::toupper);
或者,如果你没有基于的范围,你可以使用for_each
:
std::for_each(std::begin(arrayinput), std::end(arrayinput), [](string& str) {
std::transform(std::begin(str), std::end(str), std::begin(str), ::toupper);
});
您声明了一个与函数同名的变量,从而导致了歧义。如前所述,只需更改变量的名称,就可以解决它。
相关文章:
- 如何使我的 sizeof sum 结构与空参数包一起工作
- SFINAE:它如何与派生类一起工作?
- std::remove() 按预期处理文字,但不能与取消引用的迭代器一起工作
- 尝试让条形码扫描仪与Arduino一起工作
- 从书本中学习C++无法使该程序与类一起工作
- 让类与运算符一起工作更简单的方法
- 如何使lambda与std::nullopt一起工作
- 当我使用长整型时,我的代码不起作用,它与 int 一起工作得很好
- 返回对象如何与分配运算符一起工作
- GLM :: perspective()和glm :: lookat()一起工作
- SFML OpenGL:如何同时与他们一起工作
- 使QTConcurrent ::映射与Lambdas一起工作
- 如何与C 字符串中的非ASCII字符一起工作
- 我如何适应擦除式习惯与矢量元组一起工作
- 需要帮助使 VOID 代码与总工资一起工作
- 我怎样才能让这个刽子手代码与 wxDev-C++ 一起工作
- Googletest 在 bazel test 中永远不会失败(在它应该失败的地方),但与 cmake & clion 一起工作
- 常量变量初始化仅与成员初始化列表一起工作
- feal_ptr与unique_ptr一起工作
- OpenGL Ping Pong可与一张通行证一起工作,而不是两个通行证