Saturday, November 25, 2006

36. How do I use RBuf to read from a file?

This was posted by Simo as a comment here:

RBuf is also the best choice when reading strings from file. Using RBuf instead of HBufC requires less code. Also, error handling becomes more simpler.

Here is simple example how to read from RReadStream:

in .h: RBuf iSomeSetting;
in .cpp: iSomeSetting.CreateL( stream, KMaxTInt );

the HBufC would be:
in .h: HBufC* iSomeSetting;
in .cpp: iSomeSetting = HBufC::NewL( stream, KMaxTInt );
TPtr tmp( iSomeSetting->Des() );
stream >> tmp;

Error handling is also easier because there are no NULL pointer checks required for RBuf.

This page is powered by Blogger. Isn't yours?

WWW Descriptors FAQ