That's 4 MB of binary integer data. 5 MB if you count the newlines. If you like the data in binary, just write it out to wherever as binary values.
I'll assume you need formatting as well. The best way to do this then is to allocate a "huge" string which is big enough to handle everything, which in this case is 10+1 chars per integer. This means 11 MB. That is a reasonable memory requirement and definitely allocatable on a normal desktop system. Then, use sprintf
to write the integer values out to the string:
#include <cstdio>
#include <iostream>
#include <string>
int main()
{
std::string buffer(11534336, '\0');
for (int i = 0; i < 1048576; ++i)
{
std::sprintf(&buffer[i * (10 + 1)], // take into account the newline
"%010d\n", i);
}
std::cout << buffer;
}
Note the effective formatting operation is very fast.
The physical output to the console window will take some time on Windows, this is inherent to the Windows console and cannot be remedied. As an example, Coliru times out after 17872 entries, which I believe is 5 seconds. So unfortunately, printing to the screen at this speed is impossible using Standard C(++). You might be able to do it faster when you do everything on the GPU directly and display a surface/texture/image you create, but that can hardly be the point of the exercise.