So I'm trying to write a code for a units converter based on user input for the value and the units. This code sometimes reads the input properly and prints the value and the units correctly, but sometimes it doesn't read either input. It doesn't seem to matter if there is a space between the numbers and the units in the input whether the code reads properly or not. But, I would like the space to not matter(e.g. "12m" vs "12 m")
#include <iostream>
#include <string>
using namespace std;
int main()
{
string units;
double val0 = 0;
cout << "input value and units\n";
cin >> val0 >> units;
cout << "value: " << val0 << "\nunits: " << units << endl;
return 0;
}