Storing A Range of Numbers in An Array

A while ago, I read that there was a way to store many values in an array without using a loop, but I cannot remember the syntax. It was something like this.

1
2
3
4
5
6
7
8
  #include <iostream>

using namespace std;

int main() {
	int line [100] = {1 .. 100};
}


This would take every number from one to a hundred and store it as an individual element in the array. I have looked everywhere on the internet for when I first saw that, but I cannot find it. Is there any way to store all the numbers from 1 to a 100 in an array without using a loop? Thanks.
Well, there's std::iota, but this isn't a language feature. There are no ranges nor list comprehensions in the core language.
1
2
int line[100]; 
std::iota(std::begin(line), std::end(line), 1);

Prefer std::array over C-style arrays.
Last edited on
Topic archived. No new replies allowed.