I am just wondering if there any replacement in c++ for sscanf?
Below is the lines of code which I need to replace sscanf. Any idea? Should I use std::sscanf?
I suppose one should point out that you don't need to replace anything. "If it ain't broke, don't fix it."
Should I use std::sscanf?
It's the same function, just wrapped in the std namespace, so you wouldn't be changing any functionality by doing this.
The high-performance, C++ method for this type of parsing would probably be std::from_chars, but it isn't really one-to-one with sscanf, since I don't think it let's you parse 42 out of "ijk 42 xyz". https://en.cppreference.com/w/cpp/utility/from_chars
But for your purposes, if it's a simple float or int you need to parse, it will still work.
It's the same as your original post. Not better or worse. It's the same functionality.
If we want to get into the nitty gritty (not necessary, probably will just confuse you): Strictly speaking, if you are #including <cstdio>, then it's not guaranteed that those functions will be in the global namespace, so prepending std:: is safer, but all compilers that you'll ever encounter will be perfectly fine without the std::.
Here is a complete C++20 (17?) example using from_chars:
It's also worth bearing in mind for robust code that scanf type functions do not detect numeric overflow or underflow, which these methods do (as Ganado shows).