int main()
{
Vector3D firstVector = Vector3D();
Vector3D secondVector = Vector3D();
cout << "Enter two vectors in format (x, y, z): " << endl << "First Vector is ";
cin >> firstVector;
cout << "Second vector is ";
cin >> secondVector;
Vector3D sumVector(firstVector + secondVector);
cout << endl << sumVector << endl;
return 0;
}
And this is the istream inplementation:
std::istream& operator>>(std::istream &iStream, Vector3D &vector)
{
iStream.ignore();
iStream >> vector.m_X;
iStream.ignore(2);
iStream >> vector.m_Y;
iStream.ignore(2);
iStream >> vector.m_Z;
return iStream;
}
I theorize, based on your prompts, that the input would be something like, say, (5, 2, 5) and your overload for the stream extraction operator:
(1) Ignores "("
(2) Puts 5 into X
(3) Ignores ", "
(4) Puts 2 into Y
(5) Ignores ", "
(6) Puts 5 into Z
(7) Returns the istream object.
However, you haven't discarded ")\n" from the stream after you read in vector.m_Z, so that remains in the input buffer until the next read, which is throwing off the input of your second vector.
After you assign to vector.m_Z, consider ignoring whatever else is in the input stream with:
That way, if the program works, we've narrowed the issue down to the input stream retaining additional characters in the input buffer and can refine the last ignore statement to be more precise with all of the bells and whistles. Let me know how that goes.
With iStream.ignore(1000); is not better because it wants to be typed a thousand symbols before countinue running, but I tried with iStream.ignore(2) and it works properly. Thank you very much for your help :)