for loop how to use index

What everyone else said.

Arrays are a basic part of the C++ programming language. You probably need to google "C++ tutorial" and do a C++ tutorial, rather than cutting and pasting bits of sample code.