You are opening the file before the loop. Since you are updating the filename
variable inside the loop, I suppose you want to open it each time you pass through the loop.
Move the line :
ifstream inFile(fileName);
to one line before the test:
if (!inFile)
Also, the place where you code ifstream inFile(fileName);
you have an empty string in fileName
(You didn't initialize the variable passed as argument in main).
Also, you are passing a int k
parameter to the function but never uses it there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…