错误 没有与参数列表 C++ 匹配的重载函数"getline"实例

error no instance of overloaded function "getline" matches the argument list c++

本文关键字:重载 函数 getline 实例 参数 C++ 列表 错误      更新时间:2023-10-16

error重载函数"getline"的实例与参数列表不匹配

我似乎看不出哪里出了问题。我觉得我在传递正确的论点(即std::ofstreamstd::string)。任何帮助都将不胜感激。

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main () {
  ofstream myfile;
  ofstream yourFile;
  myfile.open ("read.cc");
  yourFile.open ("write.cpp");
  string line;

这一部分尤其是出现错误的部分。

  if (myfile.is_open()){

while循环中的getline是红色的,并且给出了重载错误。

      while(getline(myfile,line)){
          yourFile << line <<"n";
      }
  }
  myfile.close();
  yourFile.close();
  return 0;
}

我以为我已经正确地设置了溪流。

输出流用于写入。对于从中读取,您需要一个输入流:

std::ifstream myFile;
//   ^^