File handling

Can i use the same file handle to read and write in different files.
i mean to say that if i have a handle to a file (of type fstream ) lets say file1 from which i am reading something and i am using the same file handle to write in some other file file2. Is this possible? or the file handle i am using is valid only for reading and writing in the same file i.e in same file1.
No. A file handle represents a single file. It cannot represent two files at the same time, not even if you are performing the exact same operation (i. e. reading).
But with the same handle we can perform reading and writing in the same file.right?
Yes, however IIRC the read/write pointers are separate, so you need to make sure you are reading/writing where you want to. Although what are you doing that would require you to read/write from/to the same file at the same time?
Thanks webjose and firedraco for your help.
can you please look into this

http://www.cplusplus.com/forum/general/18986/
what if you make a wrapper function to write and read the file.. i mean when you call that function its should automatically open the file then write what needs to be written and close it after..
@blackcoder '

if you are talking about this http://www.cplusplus.com/forum/general/18986/
then i did the same, can u please look into the same.


Topic archived. No new replies allowed.