make member function of class that returns the no. of an array

Hi guys! I want some help with my class here! I created a class that takes an input file with numbers (.dat or .txt)! The problem is that i want to create a seperate member function which will return the number of the elements of my function to use that number for another class!
Hope u can help me and thanx anyway :)


#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;


class ReadTheFile{ // class which reads numbers from a file into an array



public:


int countNumbers;


ReadTheFile() // constructor with the file name to read
{

filename = "ah.txt"; //This is the file to read.
ifstream f(filename.c_str());
if (!f) { cout << "can't find " << filename << endl; exit(1);}


}


string publicArray(char * args[100]) // member function public array
{



ifstream f(filename.c_str());
if (!f) { cout << "can't find " << filename << endl; exit(1);}

countNumbers=counnting;
countNumbers=0;

int n; // the number each time

bool read = true; // loop control, as long as read is true the loop continues to read the numbers


while (read) // loop until we run out of file.
{
f >> n; // read a number. It might fail, but
if (!f.eof()) // we can test to see if it has reached past end of file
{
cout << n << endl; // debugging
countNumbers++;
}
else // Done. Terminate the loop, and close the file.
{
read = false;
f.close(); // dont forget to do this!
}
}


cout << n << endl; // so the code dont miss the last number
countNumbers++;


cout<<"The number of numbers is:\n"<<countNumbers<<endl;

exit(countNumbers);

}



private:

int counnting;
string filename;

};
Topic archived. No new replies allowed.