In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to achieve an IP address class in C++", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve an IP address class in C++" article.
[project-IP address Class]
The IP address used in the Internet occupies 4 bytes and can be expressed as a four-segment method. The range of values for each segment is 0-255. the middle is "." Separate, for example, 202.194.116.97. In fact, you can also look at an unsigned integer value of 3401741409 with 4 bytes.
Now design an IP address class to save the IP address and implement some operations on the IP address. As follows:
Class IP {private: union / / as can be seen from the anonymous consortium, IP addresses occupy a total of 4 bytes {struct / / this is a 4-byte anonymous structure {unsigned char seg0; unsigned char seg1; unsigned char seg2; unsigned char seg3;}; / / 4-byte IP addresses can be regarded as four parts, each part 1 byte unsigned int address / 4-byte IP address can be regarded as a 4-byte whole}; public: IP (int=0,int=0,int=0,int=0); / / constructor void showIP (); / / display IP address bool sameSubnet (const IP & ip, const IP & mark) by four-segment method; / / determine whether it is in the same subnet char whatKind (); / / return to which type of network} / / implement member functions int main () {IP ip1 (202, 194, 116, 97), ip2 (202, 194119102), mark (255, 255, 248, and 0); cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.