problem in linux with respect to file stream reading
1)I was reading the file into a buffer and I used the following code as follows:-
if ( inputFile.is_open() )
char* data = new char[fileSize]; // create buffer to read data from the file
inputFile.read( data, fileSize );
I am trying to call above code once for file A and second time for file B. For file A its working fine, for File B ; it gives segmentation fault as soon as control hit the read function for file B.The problem was coming in release mode, its working fine in debug mode. To get rid of this read function's failure I replaced these above stream function with Fread, Fopen C file reading function and I am able to read the file in to buffer for both file A and File B.
2) Once I am able to solve problem by using fopen, Fread etc functions, then I am facing problem in following code:-
stringstream str( string( data , fileSize ) );
while( getline( str, s ))
// perform some opertaion on s
The getline function was failing for file B , its working fine for File A (where all the file data exist in the buffer data, which I checked by printing the data), again the problem coming in release mode , debug mode is working fine.
Thanks & Regards