How to do 6input file?

How can I put 6 input file into my program.How can I use while to let the 6input file to open automatic?Please help me.
Thank you very much.
Maybe you can try with an ifstream vector, but I don't think it's the best way... I don't even know if it works...

ifstream infile[6] = {"file1", "file2", "file3", "file4", "file5", "file6"};
Last edited on
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
#include <stdlib.h>
using namespace std;

void main ()
{
int a,b,c,i;
ifstream input_data[2]={input_data[0],input_data[1]};
input_data[0].open("input.txt0", ios::in);
input_data[1].open("input.txt1", ios::in);
for (i=0; i<2 ; i++){
if (input_data[i].fail()){
cerr << "Can't open input file "<<endl;
exit(-1);
}
while(!input_data[i].eof())
input_data[i] >> a >> b >> c;
cout << a << b << c << endl;
input_data[i].close();
}
_getch();
}
Is it like this?Thank you for you reply.
Yes something like this should work, but at least I noticed that you can simple declare the ifstream vector like this:
1
2
3
ifstream input_data[2]
input_data[0].open("input.txt0", ios::in);
input_data[1].open("input.txt1", ios::in);

Sorry, it was my fault.
thank you very much
Topic archived. No new replies allowed.