0
#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:'{';我怎樣才能給這個結構裏面的結構體賦值?
addr.bytes =(bytes_t){192,168,0,96};不適用於MSVC 2010. – Huy
感謝您的及時回覆,Rasen。 – user2565838
它不起作用,同樣的錯誤出現... – user2565838