In c++ there is no requirement to declare all variables on the top of a function. Especially the counter variables should go in their local scope. It is a good practice to define any declared variables on the same line.
Please, if there are no need, declare and define the variables in the appropriate scope.