I\'m trying to collect user\'s input in a string variable that accepts whitespaces for a specified amount of time.
Since the usual cin >> str does
cin >> str
My guess is that you're not reading n correctly, so it's converting as zero. Since 0 is not less that 0, the loop never executes.
n
I'd add a bit of instrumentation:
int n; cin >> n; std::cerr << "n was read as: " << n << "\n"; // <- added instrumentation for // ...