getline();使用C++时出错
getline(); error using C++
当我尝试运行以下程序时,我从getline()
调用中得到以下错误。
消息是:
In function 'int main()':
error: no matching function for call to 'getline(std::ofstream&, std::string&)'
我不知道我为什么得到这个——我有string
库。
我的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int NumeroLetras;
cout << "Juego de El Ahorcadon--------------------n" << endl;
cout << "N243mero de letras de la palabra: ";
cin >> NumeroLetras;
/* Creamos el fichero con las palabras a adivinar
------------------------------------------------------------------------*/
cout << "Creando fichero con palabras..." << endl;
ofstream fichero("palabras.txt");
fichero << "balonceston";
fichero << "beisboln";
fichero << "futboln";
fichero << "golfn";
fichero << "rugbyn";
fichero << "tenisn";
fichero << "boxeon";
fichero << "sumon";
fichero << "judon";
fichero << "nascarn";
fichero << "atletismon";
fichero << "caminatan";
fichero << "ciclismon";
fichero << "esgriman";
fichero << "natacionn";
fichero << "polon";
fichero << "clavadosn";
fichero << "remon";
fichero << "velan";
fichero << "ajedrezn";
fichero.close();
cout << "Fichero creado exitosamente..." << endl;
/* Determinamos el tamaño de las palabras
------------------------------------------------------------------------*/
string Palabra;
fichero.open("palabras.txt");
while (! fichero.eof())
{
getline(fichero, Palabra);
cout << Palabra << endl;
}
return 0;
}
为什么我会出现这个错误?
您正试图从ofstream
(输出文件流)读取
创建一个新的ifstream
变量并从中读取。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 为重写std::exception的库生成swig接口时出错
- 导入/导出变量时出错
- PrintWindow函数在notepad.exe中出错