我研究了各种方法,从 string.erase/ispunct 等,但我不能简单地让它在我的代码中工作。
我的代码如下:
ifstream infilei("test.txt")
**Second part of code......**
while ( !infilei.eof() )
{
string wordlist;
infilei >> wordlist;
inputlist.push_back(wordlist);
}
text.txt中包含逗号、单引号、双引号等,需要去掉。
在显示 infilei >> wordlist;
的地方,我尝试使用 if 语句删除带有 '"' 等的字符串,但它仍然没有删除单引号或双引号。是否还有另一个或者我可以设置一个 string.erase 超过某个 ascii 范围吗?还有一种方法可以在 push_back 期间将字符串发送为小写吗?
谢谢
最佳答案
你应该像这样写 if 语句 if(str[i]=='\"' or str[i]=='\'')
至于小写应该这样做它:
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
关于c++ - 从字符串c++中删除单引号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9811890/