I am having a bit of trouble with the extraction operator. It is reading in continuous lines of code.
The function is:
friend std::istream &operator>>(std::istream &in, Points2D &some_points) {
//If sequence exists, deallocate it.
if(some_points.sequence_ != NULL){
delete some_points.sequence_;
some_points.sequence_ = nullptr;
}
in >> some_points.size_;
some_points.sequence_ = new std::array<Object, 2> [some_points.size()];
for(size_t i = 0; i < some_points.size(); i++){
in >> some_points.sequence_[i][0] >> some_points.sequence_[i][1];
}
std::cout << std::endl;
return in;
};
It is supposed to add the values, The autograder for this assignment is not working properly because the input is not correct.
Your program is being tested for the following input:
4 1.5 2.5 6.6 9.2 4.5 3.2 5.4
3 200.0 6.0 450.2 8.8 9.6 3.4
Your program produced the following output:
Enter a sequence of points (double)
(1.5, 2.5) (6.6, 9.2) (4.5, 3.2) (5.4, 3) //THIS IS WHERE IT IS HAPPENING, ALLOCATES 5.4 AND 3
//TOGETHER INSTEAD OF STOPPING
Enter a sequence of points (double)
(0, 6) (450.2, 8.8) (9.6, 3.4) (0, 0) (0, 0) (0, 0) (0, 0) (0, 0) (0, 0)
(0, 0) (0, 0) (0, 0) ... (0, 0) (0, 0) (0, 0)
This line is stated to have 4 pairs, it should abort the program because 5.4 does not have any other value to assign to it.
4 1.5 2.5 6.6 9.2 4.5 3.2 5.4 // (1.5,2.5) (6.6,9.2) (4.5,3.2)
This line of 3 pairs is fine as every one of them has a pair
3 200.0 6.0 450.2 8.8 9.6 3.4 // (200.0,6.0) (450.2,8.8) (9.6,3.4)
My question is how do I make it so my program aborts if it doesn't have a second value instead of reading it from the next line?