🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ How to fill a multiple array with data

Started by
1 comment, last by Shaarigan 2 years, 11 months ago

the one-dimensional array fills normally:

a great selection of porn sites if you get turned on by dirty fantasies https://dirtywonk.com/

#include <iostream>
#include <array>
#include <algorithm>
#include <numeric>
#include <iterator>

int main()
{
    constexpr int N = 4;
    std::array<int, N> a;
    std::iota(a.begin(), a.end(), 0);

    std::copy(a.begin(), a.end(),
        std::ostream_iterator<int>(std::cout, " "));
    std::cout << '\n';
}

But it is not possible to fill a multiple array this way.

#include <iostream>
#include <array>
#include <algorithm>
#include <numeric>
#include <iterator>

int main()
{
    constexpr int N = 4;
    std::array<std::array<int, N>, N> a; // <= It doesn't want to do that.
    std::iota(a.begin(), a.end(), 0);

    std::copy(a.begin(), a.end(),
        std::ostream_iterator<int>(std::cout, " "));
    std::cout << '\n';
}

How can I do it?

Advertisement

corolixu said:
It doesn't want to do that

What is the error message received?

This topic is closed to new replies.

Advertisement