How to read string with whitespace in C++?

scanf ("%[^\n]%*c", str);
Works unless you have overflown the limit like there is a question in HackerRank’s 30 Day Challenge, where taking Double before string creats problem in getting a string with spaces