Previous declarations

closed account (NUj6URfi)
I am using multiple ifstream loads and it claims to be prviously declared so it stops my compilation. What can i do about that?
You should do what the compiler says.:)
closed account (NUj6URfi)
And that is? I need to open multiple files.
You can't use the same name for all your ifstream objects, otherwise how would you (or the compiler) be able to tell them apart?

1
2
3
4
5
ifstream file1("some file.foo");
ifstream file2("another file.foo"); // <- note it has a different name

ifstream file1("error.err"); // <- this will be a compiler error because you already
   // have a 'file1' object 
@Disch

You can't use the same name for all your ifstream objects, otherwise how would you (or the compiler) be able to tell them apart?


You can use the same name for all your ifstream objects if they are processed sequentially.:)
Moreover you can place all them into std::initializer_list and use the range-based for statement to process them.
I'm making assumptions about what the OP's problem is based on what he said in his post.

OP wrote:
multiple ifstream loads and it claims to be prviously declared


I interpreted this to mean he has multiple ifstream objects with the same name. Hence why I replied with the response I did.

So yeah.. you're right... you can certainly use the same ifstream object to open multiple files in sequence... but I did not interpret OP's problem that way.
Last edited on
@Disch


I wanted simply to append your response that there are several approaches depending on the design of the program.:)
Ah okay. ^^

It would've been helpful if OP was a little more clear with his problem so we could answer it more directly.
Last edited on
Topic archived. No new replies allowed.