The last statement creates a temporary stringstream and then uses it to parse the string as a hexadecimal format in iMask.
There are flaws with it, although there is no way to verify that the streaming was successful, and the last stream does not achieve anything, since you are dealing with a temporary one.
It would be better to create a stringstream as non-temporary, ideally using istringstream, since you only use it to parse the string for int, and then to verify that the conversion completed successfully.
std::istringstream iss( strMask ); iss >> std::hex; if(!( iss >> iMask )) {
You only need to set the mode back to decimal if your stringstream will now parse the decimal integer. If it parses more than hexadecimal, you can just read them too, for example, if you have a bunch of files.
How you handle errors is up to you.
std::hex and std::dec are part of the <iomanip> streams that indicate how text is formatted. hex means hexadecimal, and dec means decimal. The default is decimal for integers and hexadecimal for pointers. For reasons unknown to me, there is no such thing as a hexadecimal representation for printing float or double, i.e. There is no "hexadecimal point", although support for C99 supports it.
source share