well im stuck again and its because of classes again. i have the follwing program that works fine but i need to make a class and use the code as a function of that class
this is what i have so far but it gives me a few errors, and im totally lost, someone help me out?Code:#include <iostream.h> #include <fstream.h> #include <stdlib.h> display a file on the screen int main(void) { const int FileNameLen = 30; // Constant int ifstream infile; // file object char filename[FileNameLen]; // Store the filename // as a character string char inchar; //Read a character at a time // Get the file name cout << "Enter file name ->" << '\t' ; cin >> filename; // Open the file infile.open(filename); if (!infile) { cerr << "Cannot open " << filename << endl; exit(1); } // Read the file while (!infile.eof()) { inchar = infile.get(); cout << inchar; //display it on screen } infile.close(); //Close the file return(0); }
Code:#include <iostream.h> #include <fstream.h> #include <stdlib.h> const int FileNameLen = 30, ArrayLen =4; // Constant integer class array { public: int readarray(); array(); private: ifstream infile; // file object char filename[FileNameLen]; char inchar; //Read a character at a time }; array::array() { } // display the file int readarray() { // Get the file name cout << "Enter file name ->" << '\t' ; cin >> filename; // Open the file infile.open(filename); // If you can't open the file, print error message if (!infile) { cerr << "Cannot open " << filename << endl; exit(1); } // Read the file while (!infile.eof()) { inchar = infile.get();//This reads in cout << inchar;//Display it on screen } infile.close(); //Close the file return(0); } int main() { array Numbers; int nums = Numbers.readarray(); cout <<"The numbers in the array "<< nums << endl; return 0; }



LinkBack URL
About LinkBacks



. i clicked the line under the error and i read it, then i clicked List members and looked all the memebers and only "open" was a valid assumption so i used it and it worked.