The below peice of code does not work when run in codepad.org. I searched online to find what exactly will happen on memcpy of structures with C++ string.
#include <iostream>
using namespace std;
typedef struct {
int i;
std::string data;
} ST_INFO;
int main ()
{
ST_INFO stInfo1, stInfo2;
stInfo1.i = 1;
stInfo1.data.assign("test");
memcpy(&stInfo2, &stInfo1, sizeof(stInfo2));
cout << "data" << stInfo2.data.c_str();
return 0;
}
I couldn't get succint answers. While searching for answers I ended up with more questions.
Additional Question:
1) How the memory allocation and deallocation happen for strings. 2) what will happen on memset of structures with C++ string is done.
Could anyone here please help me?