I suggest you use `stringstream` here similar to the code below, that is safer