iSpunct()未检测到单引号字符
ispunct() does not detect single quote character
我正在尝试在文件中读取并从文件中删除所有标点符号。我一直在使用iSpunct()通过字符串迭代,并检查字符是否是标点符号,但似乎并没有捕获所有标点符号。我想知道我是否做错了。这是我的代码:
2.TXT
你好吗?
我很好,谢谢。
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
//removes punctuation, numbers, and extra spaces
void removeNonAlph(string &tmp)
{
for(int i = 0; i < tmp.length(); i++)
{
if (ispunct(tmp[i]))
tmp.erase(i--, 1);
else if (isdigit(tmp[i]))
tmp.erase(i--, 1);
else if ((tmp[i] == ' ') && (tmp[i+1]) == ' ')
tmp.erase(i--, 1);
}
}
int main(int argc, const char * argv[])
{
ifstream file("2.txt");
string tmp;
string words[500];
while (getline(file, tmp))
{
removeNonAlph(tmp);
toLower(tmp);
cout << tmp << endl;
}
file.close();
}
输出:
你好吗
我很好,谢谢
(注释移动以回答未来读者的轻松发现)
提防编辑器将非ASCII引号放入您的文本文件中。许多编辑者生成的"智能引号"通过使用不同的非ASCII角色代码渲染的右图和左引号来看起来更好。ispunct
通常仅适用于ASCII输入。
相关文章:
- 单引号在C++数学编程中是什么意思?
- wcout不会打印正确的单引号
- C++ 中数组(单引号和双引号)的可视常量字符* 与字符
- 使用带有 std::cout 的单引号打印字符串实际上打印了数字
- 匹配外部单引号之间的字符串
- 如何使用C++中不是文字的变量在数字中显示单引号和两个引号?假设 6'2" 英尺
- 正则表达式使用提升令牌迭代器在单引号和括号之间提取值
- 如何在QT中正确逃脱单引号和双引号
- 为什么'char'值必须有单引号而不是双引号?
- C++单引号语法
- 修改正则表达式以包含反斜杠和单引号(以便反斜杠表现为转义字符)
- iSpunct()未检测到单引号字符
- 以C++显示时带有单引号和双引号的不同答案
- 使用 getline() 在单引号中读取
- 在 C# 中将单引号字符串到 uint
- C/C++ 中的单引号、双引号和大小 ('a')
- PQexecParams 使用单引号失败
- 从字符串c++中删除单引号字符
- 检查字符是否为单引号.c++
- c++ std::cout当我用单引号括起字符串时打印奇怪的字符