//Add words from the file to the vector
while (inputFile >> word) {
listWords.push_back(word);
wordCount +=1; //Count the words
}
for (int i = 0; i < listWords.size(); i++) {
char *p;
p = strchr(listWords.at(i), 'c');
if ( p != NULL ) {
cout << "null";
}
}
我在这里的代码将一个相当大的单词文本文件添加到我声明为 string 的内容vector listWords
中。我想使用strchr
和其他各种 Cstring 函数来摆脱带有某些字母和字符的单个单词。我在尝试这样做时遇到错误,说“没有匹配的函数调用strchr
。” 我已经包含了库<vector> <string> <cstring> <fstream>
。很确定我的错误在于指针之间。
char *strchr(const char *str, int ch)
关于我应该在这里做什么以使 strchr 工作的任何提示?