Don't play around with casting like that unless you know what you're doing. Type punning can be tricky business, but barring transmission issues with your sockets, this should work:
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
int i1 = 12345;
char buffer[sizeof ( int )];
memcpy ( buffer, (unsigned char *)&i1, sizeof ( int ) ); // Simulate send/recv
int *pi = (int *)buffer;
cout<< *pi <<endl;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Don't resurrect a two year old thread to say "me too"! Start a new thread if you have a new question. Geez.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401