Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Trusted Contributor
Posts: 160
Registered: ‎09-13-2012
My Device: 9900
My Carrier: vodafone

File Write/Read - missing data



I am opening a file in append mode and writing a line to it. My problem is that when I try to read the file that particular line of data isn't available.


When I close and reopen the app and read the file the line of data is there. I have tried flush and close and don't know what else to try.


ofstream myfile;
myfile.open ("./data/saved.txt" ,ios::app);
myfile << saveString.toLatin1().data() << std::endl;


int readtest( char* file) {
   int linecount = 0 ;
   std::string line ;
   std::ifstream infile( file) ;
   if ( infile ) {
      while ( getline( infile , line ) ) {
	 std::cout << linecount << ": " << line << '\n' ;//supposing '\n' to be line end
	 linecount++ ;
   infile.close( ) ;
   return 0 ;