使用ctype.h(C++)处理错误
Error handling using ctype.h (C++)
我在C++中发现了库的用法,它是
ctype.h
我有一个用户输入,它是一个接受单词的字符串,并且正在使用ispunct()
进行错误处理,以不接受标点符号。但我希望ispunct()
接受"。我是否可以将参数设置为跳过"?
如果我正确理解您的问题,您希望ispunct
在'
字符上返回false。如果是这种情况,您可以直接为它编写一个自定义包装器。
int myispunct(int c) {
return c == ''' ? 0 : ispunct(c);
}
其首先检查c
是否是'
。如果是,它返回0,否则它将c
传递给ispunct
并从中返回。
不,没有,因为'''
是标点符号,而这正是ispunct()
所寻找的。您可以手动检查字符。
try
{
if ( std::ispunct(word,loc) && word != "'" )
throw string("Punctuations other then ' are not allowed!");
}
catch(string ex)
{
//error handling
}
其中word
是您的字符串。
相关文章:
- 使用返回对象的函数处理错误
- C++:处理错误,看不懂我的错误
- 如何处理错误"E1696命令行错误:无法在Visual Studio 2017中打开元数据文件"mscorlib.dll"?
- C++ 异常处理错误输出
- 信号处理错误
- 文件处理I/O C 错误
- 文件处理 - 错误:与 while 循环 (C++) 中的"运算符>>"不匹配(代码::块)
- SDL的事件处理错误
- HMODULE在重建导入地址表IAT时处理错误
- C++ 中的文件处理错误 - 调用"std::basic_fstream<char, std::char_traits<char> >::open(const char[8],
- 在处理线程时,处理错误的正确方法是什么
- 处理C++错误
- 异常处理C++错误
- CUDA图像处理错误
- 文件处理错误
- 代码::阻止资源预处理错误
- 使用模板创建类的新实例,不知道如何处理错误
- Qt 与 opencv 异常处理错误
- 提升 MSM 中的错误处理错误
- 如何处理错误“vtkTrivialProducer :此数据对象不包含请求的范围”