我想知道如何从容器中删除重复的字符串,但忽略尾随标点符号的单词差异。
例如给定这些字符串:
我们为什么会在这里?
我想得到这个输出:
我们为什么在这里?
算法:
使用std::string
了你的话。这允许您执行以下操作:
std::string word;
while (data_file >> word)
{
}
使用std::vector
含有你的话(虽然你可以使用std::list
为好)。的std::vector
,所以你不必重新分配有关担心,如果你选择了错误的大小动态增长。
要附加到std::vector
,请使用该push_back
方法。
要比较std::string
,请使用operator==
:
std::string new_word;
std::vector<std::string> word_list;
//...
if (word_list[index] == new_word)
{
continue;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句