I keep getting the following error:
Unhandled exception at 0x74BDD8A8 in FileName.exe: Microsoft C++ exception: std::out_of_range at memory location 0x004FA55C.
I've done some searching but I was not able to solve this problem. I did narrow it down to the fact that the out of range error is coming from my string fdata variable. Here is my code where error/exception occurs:
void MyClass::MyMethod10()
{
string fdata;
char num[100];
int i = 0,k=0;
unsigned int m,j=0;
inputFile.open("sec1.txt", ios::in);
inputFile >> fdata;
while (j<fdata.length())
{
while (fdata.at(j) != '+')
{
if (fdata.at(j) != '*' && j<fdata.length())
{
num[k] = fdata.at(j);
k++;
}
else
{
num[k] = '\0';
m = atoi(num);
//cout << m << endl;
MyMethod22(m);
k = 0;
}
j++;
}
MyMethod22(43);
j++;
}
inputFile.close();
outputFile.open("sec2.txt", ios::out);
while (i<index)
{
outputFile << (char)data[i];
i++;
}
outputFile.close();
CleanBuffer();
}
The sec1.txt file contains the following data
25750*23084*57475*15982*+57475*15982*+13364*15982*26260*+48840*32397*13364*15982*57475*11371*21876*+25197*
In the while() loop section my program is able to read the data correctly from the file. The problem/error/exception occurs at the point where my program takes in the last number from the file. I am guessing the problem is in the while() loop, but I am not able to figure out what's wrong. All I was able to do was to narrow down the error to string fdata being out of range after it reads the last number from the file. I was wondering if anyone can help me to solve this or suggest something which I might have missed?