I need to enter more than 10000 integers, smaller than max long long directly into console. The console accepts something more than 9000 of them using getline(cin,string). Inputting them one by one slows my program dramatically. Is there anyway that I can override the console's getline maximum input?
[Edited to include the OP's comment:]
#include <iostream>
using namespace std;
int main()
{
long long n=0,i=0,a,b;
cin>>n;
for(i=0;i<n;i++) { cin>>a>>b; cout<<a+b<<endl; }
return 0;
}
This code gives a "Time Limit Exceeded" error on the task when more than 10000 integers are inputted.
EDIT: After rewriting the code with help from one answer:
#include <iostream>
static inline int error(int n) { std::cerr << "Input error!\n"; return n; }
int main()
{
long long a,b,n; // number of colours and vertices
if (!(std::cin>> n)) { return error(1); }
for (int i = 0; i != n; ++i)
{
if (!(std::cin >> a>>b)) { return error(1); }
std::cout << a+b << "\n";
}
}
Now it gives me a Runtime Error(NZEC) on the test case with 10000+ integers
EDIT 2: I found something that would help me but it is only in C# : How to read very long input from console in C#? Couldn't find an equivalent in C++