Im trying to copy a string to a struct with memcpy and I get:
error C2440: 'static_cast' : cannot convert from 'imagesize' to 'void *'|
Code:
struct imagesize
{
unsigned short len; /* 2-bytes */
unsigned char c; /* 1-byte */
unsigned short x; /* 2-bytes */
unsigned short y; /* 2-bytes */
}; //sizeof(struct imagesize) == 7
int main()
{
std::ifstream ifs(filename, std::ios::binary);
string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
size_t pos = str.find(pattern);
if (pos != string::npos)
{
struct imagesize img;
/* using memcpy to copy string: */
memcpy(static_cast <void*> (img), &str[pos+6], sizeof(struct imagesize));
}
}