Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: comemelguevo en 17 Enero 2016, 17:24 pm



Título: Duda sobre error
Publicado por: comemelguevo en 17 Enero 2016, 17:24 pm
Hola buenas al escribir una función de leer un fichero con datos tipo subtítulo me da un error en los getline(), y pone

error: no matching function for call to 'std::basic_ifstream<char>::getline(char [80])'
     f.getline(texto);
Os dejo el programa:

void leerSubtitulos (const char nombreFichero[], Subtitulo S[]){
   const int MAX_LONG_LINEA = 80;  
   const int MAX_LINEAS = 3;
   ifstream f;
   f.open(nombreFichero);
   if(f.is_open()){
      for(int i = 0; i<contarSubtitulos(nombreFichero); i++){
         int hour,min,segs,mil_segs,numero,nLineas=0;
         char aux;
         Tiempo inicio,fin;
         f >> numero >> hour >> aux >> min >> aux >> segs >> aux >> mil_segs;
         inicio = definir(hour*3600+min*60+segs,mil_segs);
         aux = f.get(); aux = f.get(); aux = f.get(); aux = f.get();; aux = f.get();
         f >> hour >> aux >> min >> aux >> segs >> aux >> mil_segs;
         fin = definir(hour*3600+min*60+segs,mil_segs);
         f.getline();
         char texto[MAX_LINEAS][MAX_LONG_LINEA];
         for(int i = 0; i<MAX_LINEAS; i++){
            f.getline(texto);
            nLineas++;
         }
         S = definir(numero, nLineas, texto, inicio, fin);
      }
   }
   else{
      cerr << "No se ha podido abrir" << endl;
   }
}




Título: Re: Duda sobre error
Publicado por: class_OpenGL en 18 Enero 2016, 00:15 am
El método de la clase ifstream getline, según los estándares, está definido así:
Código
  1. istream& getline (char* s, streamsize n );
  2. istream& getline (char* s, streamsize n, char delim );

Tiene dos sobrecargas, y ninguna coincide con la que has usado. Para solucionarlo, tienes que poner el tamaño de la cadena de caracteres como parámetro:

Código
  1. f.getline(texto[i], MAX_LONG_LINEA)

He deducido que deberías poner texto por el for en el que está:

Código
  1. for(int i = 0; i<MAX_LINEAS; i++){
  2.    f.getline(texto[i], MAX_LONG_LINEA);
  3.    nLineas++;
  4. }