Bug fix: use std::stringstream to avoid buffer overflows.