Reputation: 21
I'm trying to make a class for adding huge integers. I have 2 arrays both of size 40 I wanted to know if there is any way I can take input with out doing the old school method:
for(int i=0;i<40;i++)
{
std::cin >> arr[i];
}
In this way I have to take input 40 times. Is there a way to take input like we do in cin.getline
?
Upvotes: 2
Views: 35
Reputation: 1602
No, you can't get an array of integers directly, since there's no overload for this type. You'll have to either use third-party library for parsing or define an additional overload for operator>>
and array. Example:
#include <iostream>
#include <array>
template <int N>
std::istream & operator>>(std::istream & is, std::array<int, N> a)
{
for(int i = 0; i < N; i++)
is >> a[i];
return is;
}
int main()
{
std::array<int, 10> ar;
std::cin >> ar;
for(auto & e : ar)
std::cout << e << ' ';
return 0;
}
Upvotes: 1