Is using memcpy() with queue<char> safe?
------ C++ code ------
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<char> qch;
char ach[100];
qch.push ('h');
qch.push ('e');
qch.push ('l');
qch.push ('l');
qch.push ('o');
qch.push (' ');
qch.push ('w');
qch.push ('o');
qch.push ('r');
qch.push ('l');
qch.push ('d');
memset (ach, 0, sizeof(ach));
memcpy (ach, &qch.front(), 5); // Is this safe?
cout << ach << endl;
qch.pop();
qch.pop();
qch.pop();
qch.pop();
qch.pop();
qch.pop();
memcpy (ach, &qch.front(), 5);
cout << ach << endl;
return 0;
}
----------------------
--- Output ---
hello
world
--------------
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn