View Single Post
Old 09-02-2002, 07:31 PM   #1 (permalink)
Blaqb0x
Registered User
 
Blaqb0x's Avatar
 
Join Date: Jun 2002
Posts: 3
Blaqb0x is on a distinguished road
pass filename to function

Hi,
Im trying to pass a file name to a function that will print out the contents of the file.

can any one see what's going wrong?

ERROR:
prac $> g++ readfileprac_function.cxx -o readfile
readfileprac_function.cxx: In function `void PrintFile (char)':
readfileprac_function.cxx:30: no matching function for call to
`fstream::fstream (char &, ios::open_mode)'
/usr/include/g++-3/fstream.h:83: candidates are: fstream::fstream ()
/usr/include/g++-3/fstream.h:84: fstream::fstream (int)
/usr/include/g++-3/fstream.h:86: fstream::fstream
(const char *, int, int = 436)
/usr/include/g++-3/fstream.h:87: fstream::fstream (int,
char *, int)
/usr/include/g++-3/fstream.h:90: fstream::fstream
(const fstream &)

-----------------------------------------------------------
/* This reads a file and putputs
* the the whole file and won't dtop until
* it finds the EOF character
* */

#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>

void PrintFile(char[256]); //prototype for function

int main()
{
char file_name[] = "testfile.dat";

PrintFile(file_name);

return 0;

}


void PrintFile(char FILE_NAME)
{



char ch; //character for holding input characters to be printed
int check_eof; // checks if the EOF is next character


fstream INFILE(FILE_NAME,ios::in);

//check to see if the file was opened correctly
if( !INFILE )
{
cout << "Couldn't open file" <<endl;
exit(1);
}

while( (check_eof = INFILE.peek()) != EOF)
{
INFILE.get(ch);
cout << ch;
}

INFILE.close();


}//end of PrintFile function
--------------------------------------------
Blaqb0x is offline   Reply With Quote