【问题标题】:error no instance of overloaded function "getline" matches the argument list c++错误没有重载函数“getline”的实例与参数列表匹配c ++
【发布时间】:2014-12-27 03:23:34
【问题描述】:

错误没有重载函数“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;
}

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

【问题讨论】:

    标签: c++ iostream getline


    【解决方案1】:

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

    std::ifstream myFile;
    //   ^^
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2013-11-17
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      相关资源
      最近更新 更多