How do you put the results of a loop into an array?

How do you put the results of a loop into an array? For example a for-loop. I came up with this but theres an error:

#include <iostream>
#include <cmath>
using namespace std;



int main(){
int i;
int a[]={i};
for(i=1; i<10; i++){
int a[]={i};}
cout <<a[i];
int b;
cin >> b;
}
1
2
3
4
const int N = 10;
int a[N];

for ( int i = 0; i < N; i++ ) a[i] = i;


Or

1
2
3
4
const int N = 10;
int a[N];

std::iota( a, a + N, 0 );

Last edited on
Thanks is there a way to do it if the value N is unknown?
You can either dynamically allocate an array when its size will be known or use std::vector.
Topic archived. No new replies allowed.