我发现 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你的字符串在哪里。