![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
Codeplug
You should call clear() as well after close().
gg
![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
tabstop
You can't declare two variables of the same name in the same scope. So the second one would just need to be an open call, not a constructor.
Yeah woops, I mistyped. Here's what I have now:
Code:
ifstream input_file( "file.txt" );
input_file.close();
input_file.clear();
input_file( "file2.txt" ); // Line 57
But still,
Code:
ex2.cpp:57: error: expected `;' before ‘open’
ex2.cpp:57: warning: statement has no effect
![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
anon
But there probably isn't much reason to go through all the trouble of reusing the fstream.
I have to open about 20 files and do various things in each. Is there a way do reuse the same ifstream, or do I have to make 20 different ifstream variables?