I am a beginner in programming, I am trying to solve the problem I encountered in my assignment. Here I want to read a file and save each word as an element in a pointer pointing array. I declared pointer in Array class and reading the file in ReadAcc class. I am trying to process it outside these two classes.
class ReadAcc {
private:
double*_customerBalanceArray;
double read1;
ifstream f;
int counter = 0;
public:
ReadAcc() {
_customerBalanceArray = new double[100];
}
int GetCounter() {
return counter;
}
void Reading(string path)
{
f.open(path);
while (!f.eof())
{
f >> read1;
_customerBalanceArray[counter] = read1;
counter++;
}
f.close();
}
double* GetPointer() {
return _customerBalanceArray;
}
void DeletePointer() {
delete[] _customerBalanceArray;
}
};
int main()
{
ReadAcc read;
read.Reading("acc.txt");
for (int i = 0; i < read.GetCounter(); i=i+2)
{
//cout << "Acc# " << *(a.getCustomerBlanceArray) << " Balance: " << *(a.getCustomerBlanceArray) << endl;
}
read.DeletePointer();
}
When it compiles, the error says Exception thrown: read access violation.
Access violation writing location 0x013CE000. The pointer _customerBalanceArray value is now 0x013CE000. I do not know where it went wrong. Please help me. Thanks a million!!!