Hi guys!
I'm having a problem with a project in which I analize a .cpp file for certain reasons and I need to create a ifstream Class Variable but I can't!

Here in the header I declare the variable, look:

#ifndef ANALIZADOR2702010
#define ANALIZADOR2702010
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Analizador{

  private:
     bool archivoCargado;
     int eleccion;
     [B]ifstream archivo;[/B]

  public:
     Analizador();
     ~Analizador();
     void menuOpciones();
     void cargarArchivo();
     void compilarArchivo();
     void ejecutarArchivo();
};
#endif

Now in the .cpp I try to initialize that variable named "archivo"

void Analizador::cargarArchivo(){
  char* nombreArchivo = new char[30];
  while(!archivoCargado){
    cout<<"Escriba el nombre del Archivo que desea abrir"<<endl;
    cin>>nombreArchivo;
    [B]archivo(nombreArchivo);[/B]
    if(!archivo){
     cerr<<"El archivo escrito no existe"<<endl<<endl;
    }else{
      archivoCargado = true;
    }
  }
}

This is the error message from the compiler:

C:...\Analizador.cpp|46|error: no match for call to `(std::ifstream) (char*&)'|
||=== Build finished: 1 errors, 0 warnings ===|

I need that ifstream class variable but I have no idea how to create it =(
It would be great if you guys can give me a hand with this issue =)
Thanks!

Recommended Answers

All 3 Replies

archivo.open(nombreArchivo);

Wow, very simple!
Thanks bro! :D

Wow, very simple!
Thanks bro! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.