Aug 22, 2010 at 1:32pm UTC
Hello,
i'm trying to make a little code i have more efficient and faster.
I have a program wich opens a number of text files and make some operations in a similiar way as described above:
-Open text file 1.txt
-Operation 1
-Open again text file 1.txt
-Operation 2
-Open again text file 1.txt
-Operation 3
As you see, i open multiple times the same file , using
ifstream file;
file.open("1.txt");
The question is, can i pass this ifstream file as an argument to other functions (using it without having to open and close the streams)?
Or is there any other way that works better ( like passing the content of the stream to a string and thus close the stream ) ?
Regards,
Fisher
Aug 22, 2010 at 2:24pm UTC
It's ok to pass a stream as a function argument.
Aug 22, 2010 at 4:03pm UTC
But i can only pass it by reference , what if i want a copy of the stream ( in order to preserve the original content ) ?
Aug 22, 2010 at 6:13pm UTC
She fstream is not the contents of the file, it simply contains the means to access the content of the file. If you want to copy the contents of the file you need to do that manually.