Extract integer value from STL string
I have a file cached in memory in a variable of type std::string. The first two bytes in hex are 12 00, which give the length of a substring within the buffer following these two bytes.
How can I copy the value of these two bytes to an integer variable directly from the buffer (NOT from the original file), giving it the value 18? I don't want to use vectors or kind of special data structures besides a standard STL string. Just need a simple one or two liner to do it.
I'm tempted to just say
Code:
memcpy(&len, buffer.c_str(), 2);