O più semplicemente potresti usare la fgets.
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum