#include <iostream>
#include <stdint.h>
using namespace std;
union ipv4 {
struct bytes{
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
} bytes;
uint32_t int32;
};
int main( int argc, char ** argv ) {
union ipv4 addr;
addr.bytes = { 192, 168, 0, 96 };
printf("%d.%d.%d.%d - (%08x)\n",
addr.bytes.a, addr.bytes.b, addr.bytes.c, addr.bytes.d,
addr.int32);
getchar();
return 0;
}
错误:c:\users\yayun.xie\documents\satmap\c++onlinematerial\exercise files\chap05\union.cpp(18): error C2059: syntax error: '{';