C++ toupper () 不起作用
C++ toupper () doesn't work
我不知道为什么它在我的程序中不起作用。tolower()
正常工作。现在我不知道toupper()
是如何工作的,我认为它起作用为tolower()
。
#include <iostream>
#include <cctype>
int main ()
{
using namespace std;
char ch;
while (ch != '@')
{
cin >> ch;
if (isdigit (ch))
cout << "";
else if (isgraph(ch) )
{
ch = tolower (ch);
cout << ch;
}
else
{
ch = toupper (ch);
cout << toupper (ch);
}
}
return 0;
}
函数std::isgraph
如果字符具有图形符号,则返回true。然后,所有可见字符再次将true
作为来自此功能的输出,因此所有人都会击中tolower
。如果将所有迹象显示为std::tolower
?
在此处检查std::isgraph
。
如果您在程序中输入角色,天气是一个较低的案例或上限字母,它将始终在第一个其他陈述中结束:
else if (isgraph(ch) )
{
ch = tolower (ch);
cout << ch;
}
因此,您必须首先检查输入是否在上/下情况下。例如,Isupper和Islower应该有帮助。
#include <iostream>
#include <cctype>
int main ()
{
using namespace std;
char ch;
while (ch != '@') {
cin >> ch;
if (isdigit (ch)) {
cout << "this was a digit" << endl;
}
else if (isgraph(ch) && isupper(ch)) {
ch = tolower (ch);
cout << ch << endl;
}
else if (isgraph(ch) && islower(ch))
{
ch = toupper (ch);
cout << ch << endl;
}
}
return 0;
}
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++ toupper () 不起作用
- isupper(), islower(), toupper(), tolower() 函数在 C++ 中不起作用
- toupper() 在 for 范围循环中不起作用