Help opening files in double for loop
I am trying to open a file in a double for loop using the variable of the first loop as the directory and the second variable as the file.
1 2 3 4 5 6 7 8 9
|
for(int i = 0; i < variable; i++)
{
for(int j = 0; j < variable2; j++)
{
ifstream fin;
fin.open(i / j);
//read data from file
}
}
|
You could use a std::ostringstream to convert your numbers into strings a bit like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for(int i = 0; i < variable; i++)
{
for(int j = 0; j < variable2; j++)
{
ifstream fin;
ostringstream oss;
oss << i << '/' << j;
fin.open(oss.str().c_str());
//read data from file
}
}
|
http://cplusplus.com/reference/iostream/ostringstream/
Do I have to include a library to use it?
Last edited on
Thanks I got it working now.
Topic archived. No new replies allowed.