Reading and writing
The C++ standard iostream library earned a reputation of being rather sluggish. I won't bash iostream here, as it is doing much more than only reading data, namely the locale dependent conversion and formatting, but the fact is that some of its older implementations may be slow.
Should you encounter problems with performance of a standard stream such as std::cin or std::cout, try to untie and unsynchronize it. You could try to increase buffer sizes in the case of file streams. Setting the locale back its to default (that is, the C locale) will avoid the locale-based conversions. You could also use std::filebuf directly or through std::getline() to avoid conversions and formatting overhead. Using the C functions fgets() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access