Using the loop integer to define variables: c++

前端 未结 3 1365
忘掉有多难
忘掉有多难 2021-01-16 12:09

I have a for-loop which runs over i. For every iteration, I wish that it creates a variable with the name var_i i.e if my loop runs over i=0<

3条回答
  •  再見小時候
    2021-01-16 13:11

    You can also use an array of the required size and initialize it with a default value in the loop

    int var[4];
    for(int i=0; i < 4; i++){
        var[i] = 0;
    }
    

提交回复
热议问题