空间字符函数
Isspace Character Function
我是新手,目前正在学习C++。我目前正在学习cctype(ctype(中的字符函数。我很难理解为什么isspace(a_character(不返回我的cout消息 - 问题是它甚至不接受我的Char用户输入。任何帮助或转向正确的方向将不胜感激。如果我分配 Char 值:",我可以实现我想要的响应,但是,它违背了目的。我已经复制了部分代码。据我了解,空白没有确切的符号?如果是这样,是否可以输入空格作为输入?我尝试输入:"但是,没有成功。再次,我将不胜感激。
#include <iostream>
#include <cctype>
#include <ctype.h>
using namespace std;
int main()
{
char c ;
char ans = 'y' || 'Y';
do {
cout << "Enter a character n";
cin >> c;
if (isspace (c)) //Having trouble get this to actually produce a value
{
cout << "Your character " << c << "is a whitespace";
}
if (ispunct(c))
{
cout << c << " is a punctuation charactern";
}
cout << "Would you like to enter another value? n";
cin >> ans;
} while (ans == 'Y' || ans == 'y');
return 0;
}
>>
是一个格式化的提取器。默认情况下,格式化提取器在实际读取任何内容之前提取并丢弃所有空格字符。这是有用的行为,但当您尝试读取空格字符时则不然。
使用无格式输入(get()
(或noskipws
操纵器。请注意,您以后对ans
的读取很可能取决于跳过空格才能正常工作,因此,如果选择第二个选项,则可能需要在读取c
后使用 skipws
恢复跳过空格的行为。
相关文章:
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 将字符随机转换为大写的函数
- 固有构造函数的字符和访问级别
- constexpr 函数获取常量字符*
- 将字符缓冲区强制转换为函数指针
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- 将字符串数组传递给接受常量字符**的函数
- 在函数中返回无符号字符数组,但不返回指针
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- 在函数 strcpy() 中访问字符数组时出现分段错误
- 如何循环访问 cpp 中的函数返回的字符指针数组
- 自定义 std::fstream,std::filebuf 的溢出和下溢函数未为每个字符调用
- 如何在字符函数中选择某些字符?
- 使用排序函数 c++ 对字符数组进行排序
- 使用 memcpy 函数C++复制字符数组
- C++返回反向字符数组的函数
- 模板总和函数冻结字符
- 在函数内初始化无符号字符指针将返回空指针
- C++ 错误:与调用<类构造函数(字符*&、字符*&、字符*&、字符*&)不匹配