/*
 * @topic T00266 hex string to int conversion
 * @brief demonstrates usage of stringstream buffer
*/

/*
This sample demonstrates how to convert from string
that contains a hexadecimal number to a normal integer.
More on this when we cover C++ stream library.
*/
#include <iostream>
#include <string>
#include <sstream>

int main()
{
    std::string hex_num = "5A7F";  // string with hex number in it
    std::stringstream buffer;      // buffer in memory to which we can
                                   // write and read back from it

    buffer << std::hex << hex_num; // write text into the buffer

    int value;
    buffer >> std::hex >> value;   // read back an int, expecting a hex number

    std::cout << "hex:" << std::hex << value << '\n'; // display hex
    std::cout << "dec:" << std::dec << value << '\n'; // display decimal
    return 0;
}