Impossible to read a file

Hi ! Because of your help i can find if a file exists. But now it is impossible to me to go on and read the file. I think all the difficulty is in the line :
char *the_file[]=a_file.c_str ; which is wrong of course. May someone help me. Many thanks (My compiler=g++)
Here is the code of the whole :
/*ver.cpp*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "Donnez le nom du fichier à ouvrir et à lire\n";
string a_file;
cin >> a_file;
ifstream ifs ( a_file.c_str() );
char *the_file[]=a_file.c_str;
cout << the_file<<endl;
if ( ! ifs )
{
cout << "fichier inexistant\n";
return 1;
}
cout << "Ce fichier existe\n";

char x;
while ( the_file.get( x ) )
{
cout << x;
}

} // the_file is closed implicitly here by its destructor
g++ says: error array must be initialized with a brace-enclosed initializer. I cannot go on. thanks
Change this:
1
2
char *the_file[]=a_file.c_str;
cout << the_file<<endl;

to
cout << a_file<<endl;


while ( the_file.get( x ) ) -> while ( ifs.get( x ) )
The line is now char *a_file.c_str(); and g++ says : expected initializer before '.' token
/*ver.cpp*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "Donnez le nom du fichier à ouvrir et à lire\n";
string a_file;
cin >> a_file;
ifstream ifs ( a_file.c_str() );
//char *the_file[]=a_file.c_str();
char *a_file.c_str();
cout << the_file<<endl;
if ( ! ifs )
{
cout << "fichier inexistant\n";
return 1;
}
cout << "Ce fichier existe\n";

char x;
while ( the_file.get( x ) )
{
cout << x;
}

} // the_file is closed implicitly here by its destructor



You are realy a gentle guy. Every thing is now OK. I think I could never find the solution alone. Many thanks
Topic archived. No new replies allowed.