r/cpp • • 2d ago

notweerdmonk / notweerdmonk.github.io

https://notweerdmonk.github.io/technical/istream_pitfalls/

I recently wrote an article about formatted extraction using input streams in C++.

0 Upvotes

4 comments sorted by

1

u/fortsnek274 2d ago edited 2d ago

Or a better title: How to do string-to-int properly

Because, yes, I noticed that too. A bunch of string to int routines leave junk in the input. So it's not really "the whole string to int", it's more "consume int".

Same with std::stoi.

2

u/w3mk 2d ago

Much appreciated!

1

u/13steinj 8h ago

Do people actually use the input/output stream API in serious applications (post...idk, 2016)? Legitimate ask.

In the best case scenario, I have always just worked around it or wrapped it.

1

u/w3mk 4h ago

The wrappers will also use the underlying std::iostream member functions, would they not! :)

As about the workarounds, using a std::streambuf and creating a std::ifstream or a std::ofstream object is what you mean I suppose. Are you using direct operating system or C runtime functions or even the syscalls! :|

And which people are we talking about here... What is the best case scenario defined as per you?