>You cannot print the whole array in one action.
Sure you can:
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <iterator>
template <typename T, std::size_t N>
T *end ( T (&array)[N] ) { return array + N; }
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,0};
copy ( a, end ( a ), std::ostream_iterator<int> ( std::cout, "\n" ) );
}
>You cannot input a whole array in one action.
Sure you can:
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <iterator>
int main()
{
int a[10];
int *end;
// Unsafe
end = copy (
std::istream_iterator<int> ( std::cin ),
std::istream_iterator<int>(),
a );
copy ( a, end, std::ostream_iterator<int> ( std::cout, "\n" ) );
}
That's not a particularly good idea though, as it's effectively an unbounded loop, so you've got the risk of buffer overflow on your array:
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <iterator>
int main()
{
int a[10];
int *end;
end = a;
// Unsafe
while ( std::cin>> *end )
++end;
copy ( a, end, std::ostream_iterator<int> ( std::cout, "\n" ) );
}
However, you can write your own copy_n algorithm and using it still counts as one action:
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <iterator>
namespace jsw {
template <typename In, typename Out, typename Count>
Out copy_n ( In first, In last, Count n, Out dst )
{
while ( n-- > 0 && first != last )
*dst++ = *first++;
return dst;
}
}
int main()
{
int a[10];
int *end;
end = jsw::copy_n (
std::istream_iterator<int> ( std::cin ),
std::istream_iterator<int>(),
sizeof a / sizeof *a,
a );
copy ( a, end, std::ostream_iterator<int> ( std::cout, "\n" ) );
}