I was writing and reading binary file as below, when i write array to file it was writing good but when i read same array i am unable to read last array index or value.
<Writing code snip>
std::ifstream inFile(abs9.txt1);
if (!inFile) {
std::cout<<"INFO : CAN NOT BE OPEN...."<<"\n";
std::cout<<"PLEASE CHECK GIVEN INPUT FILE."<<"\n";
exit(1);
}
std::string tempLine;
std::string delimiter="\n";
std::cout<<"Record Count is :"<<recordCount<<"\n";
std::cout<<"Line count is :"<<lineCount<<"\n";
// Allocate memory to hold address of record for Index table.
pAddress=new long int [recordCount];
std::ofstream outFile("index.bin");
if (!outFile) {
std::cout<<"ERROR: COULD NOT CREATE"<<temptargetFile<<"FILE.."<<"\n";
exit(1);
}
// Read input file and write data to RVR database file line by line.
std::cout<<"INFO :STAGE1 !! "<<"\n";
std::cout<<":DATA IS BEING LOADED TO DATABASE, PLEASE BE WAIT..."<<"\n";
recordCount=0;
while ( getline(inFile, tempLine)) {
long int tempLineLength=0;
//tempLineCount=tempLineCount + 1;
tempLineLength= tempLine.length() + delimiter.length();
if (tempLine[0] == '>' || (tempLine[0] == ' ' && tempLine[1] =='>') || (tempLine[0] == ' ' && tempLine[1] == ' ' && tempLine[2] =='>')
|| (tempLine[0] == ' ' && tempLine[1] == ' ' && tempLine[2] ==' ' && tempLine[3] == '>')
|| (tempLine[0] == ' ' && tempLine[1] ==' '&& tempLine[2] ==' ' && tempLine[3] == ' ' && tempLine[4]== '>')
|| (tempLine[0] == '\t' && tempLine[8] =='>')) {
long int *pAddress=0, *pAddressStatus;
long int recordCount=6626;
std::ifstream readIndex("index.bini", std::ios::in | std::ios::out | std::ios::binary);
readIndex.seekg(0);
pAddress=new long int[recordCount];
if (!pAddress) {
std::cout<<"ERROR :MEMORY CAN NOT BE ALLOCATED TO ADDRESS ........"<<"\n";
exit(1);
}
pAddressStatus=new long int[recordCount];
if (!pAddressStatus) {
std::cout<<"ERROR :MEMORY CAN NOT BE ALLOCATED TO ADDRESS ........"<<"\n";
exit(1);
}