C++ 尝试读取文件并将某些字符串写入其他文件
C++ Trying to read through file and write certain strings to other file
dictionary.txt
有以下单词:
apple
orange
pear
kiwi
fruit
orange
plum
banana
在主要:
cin >> userIn;
userIn = tolower(userIn);
stringCheck[loopCount] = userIn;
while (fileMain >> string1) {
if (letterChecker(string1, stringCheck, loopCount) == 0){
fileDupl << string1 << endl;
}
}
在我的函数中:
int letterChecker(char string1[], char stringCheck[], int loopCount)
{
int i = 0;
for (i = 0; i<loopCount; i++){
if (strchr(string1, stringCheck[i]) == NULL){
return 0;
break;
}
}
}
目标:我希望用户输入字符。如果该 txt 文件中的单词没有用户输入的实例,我希望将该单词写入不同的文本文件(例如:用户输入"a"。"Kiwi"、"fruit"和"plum"被写入另一个 txt 文件中,因为它们没有"a"(。 我已经弄清楚如何使用清除和查找函数重置流的错误标志和位置。但是,问题是当我运行此代码时,整个列表都会写入另一个txt文件中。它似乎完全忽略了该功能。你能帮助引导我朝着正确的方向前进吗?
只需在字母检查器函数的末尾添加一个 int 值的 return 语句。
相关文章:
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 有没有办法从非C/C++文件中读取C++原始字符串文字的内容
- 如何打开并写入一个名称取自C++中字符串的文件
- 如何从二进制文件中读取字符串
- 如何在 c++ 中使用 getline 从文件中读取字符串?
- 将字符串与文件上的数据进行比较
- 用户输入字符串的文件附加问题..C++
- 如何从文件中读取两个字符串和数字数组,并将它们存储在对象向量中
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 使用文件内容作为硬编码字符串
- 将文件复制到自定义位置,存在字符串转换问题
- 在 c++ 中连接字符串和整数,以便在 C++ 11 不支持计算机的情况下读取多个文件
- 声明要在 qml 和 cpp 文件中使用的全局字符串
- C 通过char读取文件字符串的文件char;崩溃
- 我不明白如何将 toupper 和 isalpha 与.txt文件字符串输入一起使用
- 在 CPP 文件中使用 make 文件字符串变量
- 编译 PyGAMMA Mac Lion:g++ 找不到标准的 C++ 头文件(字符串/iostream..)
- 如何在c++中使用文件字符串作为命令
- 使用 TinyXML 解析 XML 文件字符串
- 递归下降解析器帮助(不读取文本文件字符串)