My task is to create a program that converts one unit of measurement to another. So if the user enters 5 kg, it converts this to the equivalent in pounds. The requirements state that the user input must be read all on one line and any number of spaces anywhere in the input must not eliminate functionality. My problem is this: if a user enters their input with a bunch of spaces between the actual double 'mass' value and then in between different words in the unit of measurement such as 'short tonnes', how can I eliminate the spacing so that it reads as just "shorttonnes"? So far my code is:
double mass; string unit;
cout << "Enter mass: ";
cin >> mass;
cin.ignore();
cin >> unit;
if (unit == "short tonnes" || unit == "sh tn")
{
//convert to long tonnes
}
My code works to ignore white space before the double mass value is entered, as well as to ignore white space up until the first part of the string is entered. But I can not figure out how to make my program read "short tonnes" as just "shorttonnes" (regardless of the number of spaces between the words), so that I can do the string comparison and convert the mass value as necessary. Thank you in advance for your help and please do not hate on me, I am in my first week of learning C++.