Changed to string streams to be able to test the code using online compilers