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).
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?
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..