Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++试图读取文件并将某些字符串写入其他文件_C++_Fstream_Iostream - Fatal编程技术网

C++试图读取文件并将某些字符串写入其他文件

C++试图读取文件并将某些字符串写入其他文件,c++,fstream,iostream,C++,Fstream,Iostream,dictionary.txt包含以下单词: 苹果 橙色 梨 几维鸟 水果 橙色 梅子 香蕉 大体上: cin >> userIn; userIn = tolower(userIn); stringCheck[loopCount] = userIn; while (fileMain >> string1) { if (letterChecker(string1, stringCheck, loopCount) == 0){ fileDupl <<

dictionary.txt包含以下单词:

苹果 橙色 梨 几维鸟 水果 橙色 梅子 香蕉 大体上:

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文件中的某个单词没有用户输入的实例,我希望将该单词写入另一个文本文件,例如:user inputs'a'。猕猴桃、水果和李子被写入另一个txt文件,因为它们没有“a”。我已经了解了如何使用clear和seekg函数重置错误标志和流的位置。但问题是,当我运行这段代码时,整个列表都会写入另一个txt文件。它似乎完全忽略了所有功能。你能帮我指出正确的方向吗?

只需在字母检查器函数的末尾添加一个int值的返回语句。

如果条件为真,字母检查器可能返回0。否则它会返回什么?似乎您最终会出现未定义的行为,因为有代码路径到达letterChecker的末尾,而没有返回语句。您的编译器是否给出了任何警告或错误消息?很好。让我加上一份报税表。我应该养成总是返回一些东西的习惯吗?而且,@Raedwald,编译器没有给出错误或警告。